我是聪明人。我试图循环一个mysql查询。
我的观点.php:
require 'libs/smarty.class.php';
$smarty = new Smarty;
include("connection.inc.php");
$query = "SELECT * FROM quickcount group by regency";
$result= mysql_db_query($db, $query, $connection) or
die("query error!");
while($res=mysql_fetch_array($sql))
{
$data[]=$res;
}
$smarty->assign('qc',$data);
$smarty->display('view.tpl');
?>
我的观点.tpl:
{section name=i loop=$qc}
<tr>
<td>{$qc[i].regency}</td>
<td>{$qc[i].vote1}</td>
<td>{$qc[i].vote2}</td>
<td>{$qc[i].vote3}</td>
<td>{$qc[i].vote4}</td>
</tr>
{/section}
上面这两个文件运行良好,但是当我想在输出表中添加一个列时出现了问题。让我们说新专栏是&#34;总和&#34; (vote1 + vote2 + vote3 + vote4)。
我在view.php中试过这个并且失败了:
$query = "SELECT * FROM quickcount group by regency";
$result= mysql_db_query($db, $query, $connection) or
die("query error!");
while($res=mysql_fetch_array($sql))
{
$data[]=$res;
$vote1 = $res[3];
$vote2 = $res[4];
$vote3 = $res[5];
$vote4 = $res[6];
$totals=$vote1+$vote2+$vote3+$vote4;
$total=array($totals);
}
$smarty->assign('qc',$data);
$smarty->assign('total',$total);
$smarty->display('view.tpl');
我也希望增加百分比。
有人可以帮忙吗?