我遵循数据库结构。
id email lat long point balance date
1 33 1.00 2.00 0 empty date
2 34 8.00 3.00 -1 empty date
3 33 7.00 4.00 2 empty date
4 33 6.00 5.00 0 empty date
5 33 6.33 5.43 -1 empty date
所以我想显示所有记录哪个电子邮件 ID 是 33,但它必须显示每一行的余额,例如。
In first row it's balance is 0
second row it's balance is 2
third row it's balance is 2
four row it's balance is 1
所以我的 php 代码看起来像这样,但无法获得正确的平衡:
echo "<table width='100%' cellpadding='5' cellspacing='0' border='1'>";
echo "<tr>";
echo "<td class='tdhead' valign='top' width='100'><b>Date</b></td>";
echo "<td class='tdhead' valign='top' width='100'><b>Lattitude</b></td>";
echo "<td class='tdhead' valign='top' width='50'><b>Longitude</b>
</td>";
echo "<td class='tdhead' valign='top' width='50'><b>Point</b>
</td>";
echo "<td class='tdhead' valign='top' width='50'><b>Balance</b>
</td>";
echo "</tr>";
while($res = mysql_fetch_array($park_history))
{
$lat = $res['lat'];
$long = $res['long'];
$point = $res['point'];
$date = $res['date'];
$balance = 0;
$sum = mysql_query("SELECT SUM(point) AS points FROM balance WHERE email =
'".$_SESSION['SESS_ID']."'");
$sum_res = mysql_fetch_array($sum);
$sum = $sum_res['points'];
echo "<tr>";
echo "<td class='tdhead2' valign='top'>$date</td>";
echo "<td class='tdhead2' valign='top'>$lat</td>";
echo "<td class='tdhead2' valign='top'>$long</td>";
echo "<td class='tdhead2' valign='top'>$point</td>";
echo "<td class='tdhead2'
valign='top'>$sum</td>";
echo "</tr>";
}
我相信可以使用 mysql sum 函数来完成。你能给我解决方案或建议吗?谢谢你。