mysqli_fetch_array()
期望参数1为mysqli_result,布尔值为-
$query = "SELECT type, SUM(price) FROM products GROUP BY type";
$result=mysqli_query($db, $query);
while($row = mysqli_fetch_array($result)){
echo "Total ". $row['type']. " = $". $row['SUM(price)'];
}
答案 0 :(得分:1)
首先,检查$db
标识符,在哪里定义连接?如果连接正常,则需要使用mysqli_error()
您应该检查$result
参数:
$query = "SELECT type, SUM(price) FROM products GROUP BY type";
$result=mysqli_query($db, $query);
if($result === FALSE) {
printf("Error: %s\n", mysqli_error($db)); // TODO: better error handling
}
while($row = mysqli_fetch_array($result)){
echo "Total ". $row['type']. " = $". $row['SUM(price)'];
}
答案 1 :(得分:-1)
使用“为”:
$query = "SELECT type, SUM(price) as sums FROM products GROUP BY type";
$result=mysqli_query($db, $query);
while($row = mysqli_fetch_array($result))
{
echo "Total ". $row['type']. " = $". $row['sums'];
}