我有这个 PHP 代码:
$count = "select
count(fruit) as total,
sum(fruit like '%apple%') as apple,
sum(fruit like '%orange%') as orange
FROM my_wonderful_table_of_fruits";
$count = mysql_query($count);
$count = mysql_fetch_row($count);
我试图将这些存储在一个变量中,但似乎无法捕捉到它们:/
我的代码是:
while ($row = mysql_fetch_array($count)) {
$count_total = $row['total'];
$count_apple = $row['apple'];
$count_orange = $row['orange'];
}
我期待能够像这样回应它们:
echo "$count_total[0] is the total of $count_apple apples and $count_orange oranges
当我在 MySQL Admin 中运行此查询时,我得到一个不错的行,如下所示:
total apple orange
5 3 2
有谁知道我做错了什么?(除了我使用的是 mysql_fetch_row 的“邪恶”版本)
非常感激!