php购物车结算总价格问题

我们想用id的个数乘以5元,然后算出总价来。
<table border="0" style="font-size:12px" width="90%" id="MyTable" bgcolor="#DFD3A0" >

<tr>
<td width="5%" align="center"> </td>
<td width="110" ><span class="STYLE3">工具名称</span></td>
<td width="230"><span class="STYLE3">工具功能</span></td>
<td width="96" ><span class="STYLE3">价格</span></td>
<td width="92"></td>
</tr>

<tbody>
<?php

$sql="SELECT t1.toolname, t1.toolfunction, t1.price, t2.username, t2.id FROM tools t1, mytools t2 WHERE t1.id=t2.mytools";
$dat = $db->query($sql);
//echo ($sql);
foreach($dat as $tool)
{
if ($tool['username'] == $_SESSION['username'])
{

?>
<tr>
<td width="5%" align="center">
<input type="checkbox" name="cid[]" id="cid[]" value="<?php echo $tool["id"]; ?>"></td>
<td width="110" ><?php echo $tool['toolname']; ?></td>
<td width="230"><?php echo $tool['toolfunction']; ?></td>
<td width="96" >    <?php echo $tool['price']; ?><span class="STYLE3">元</span></td>
<td width="92"></td>
</tr>
<?php } }?>
</tbody>
<tr>
<td>    <?php echo $['total']; ?><span class="STYLE3">元</span></td>
</tr>
</table>
<?php
//$sum = 0;
$sql = "select * from mytools group where username='$username' having count(*)>=1";
echo ($sql);
$i = count($sql);

{
$sum=$i*5;
}
echo $sum;
?>

想算出查询到的条数,但查询不出

两种办法:

1. 在foreach($dat as $tool)代码段里,设置累加器,进行价格的总价计算。

2. 使用SQL语句,再查询出某ID的总价。追问

能提供下代码?

追答

你弄点示例数据,否则不好调试

追问

方便qq吗?

追答

QQ: 951552282

温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-03-31
$x=0
foreach($arr as $key=>$val){
$x++;
}
echo x;
或select count(*) from mytools group where username='$username' having count(*)>=1
相似回答