我有2张桌子(精选,帖子)
特色表包含列(PID,价格) 帖子表包含列(USERID,PID)
我希望得到(特色中的价格)(列中的USERID)
我在PHP文件中使用了此代码
margin: 0 auto
并在tpl文件中我通过
调用它$query="SELECT sum(price) AS fp FROM featured LEFT JOIN posts ON
featured.PID=posts.PID AND posts.USERID='".mysql_real_escape_string($_SESSION['USERID'])."' ";
$executequery=$conn->execute($query);
$fp = $executequery->fields['fp'];
STemplate::assign('fp',$fp);
什么也没出来:(
答案 0 :(得分:1)
尝试此查询:
<强> SqlFiddle Demo 强>
SELECT SUM(Price) AS FP FROM posts as P
LEFT JOIN featured as F ON F.PID=P.PID
WHERE P.USERID=2
修饰:
$query="SELECT SUM(Price) AS FP FROM posts as P LEFT JOIN featured as F ON F.PID=P.PID
WHERE P.USERID='".mysql_real_escape_string($_SESSION['USERID'])."' ";
$executequery=$conn->execute($query);
$fp = $executequery->fields['FP'];
STemplate::assign('FP',$fp);
HTML:
<div class="val">
<span>
<em>${$fp}</em>
</span>
</div>