我有这段代码,我使用它来首先提取我的数据库中存在的所有用户,然后,我查询他们每个人,看看他们计算了多少点。我的问题是,分配了查询的积分的用户提取了正确的信息,但是如果一个用户没有任何积分,那么,所有这些用户都不会出现 0 分,而是给了另一个用户的积分.. 出了什么问题用我的代码?
//here i get all user id's
$query = 'SELECT * FROM users';
$result = mysql_query($query) or die(mysql_error());
$id_user = array();
$phone = array();
$name = array();
while($row = mysql_fetch_array($result)){
$id_user[]=$row['user_id'];
$phone[]=$row['phone'];
$name[]=$row['first_name'];
}
//here i get all points collected for each user
foreach ($id_user as $user_id) {
$queryuser ='SELECT SUM(basket_value) as total_sum FROM retailer WHERE user_id="'.$user_id.'"';
$resultuser = mysql_query($queryuser) or die(mysql_error());
echo "<table>";
while($row = mysql_fetch_array($resultuser)){
$total += $row['total_sum'];
echo "<tr>";
echo "<td>";
echo $total;
echo "</td>";
echo "<td>";
echo $user_id;
echo "</td>";
echo "</tr>";
}
}
echo "<table>";