我已經統計了投票給某個候選人的選民的數量,我想要顯示哪一個獲得了最高的投票數。我試圖將它們存儲在變量,這樣我就可以使用MAX()方法,但我得到了錯誤「未定義」 .ANY幫助,請PHP從mysql表中獲得最大數量
<?php
$query="select count(*) as total from voting Where ca_id=1";
//ca_id is the candidate id that voter choose
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
echo"$row[total]<br>";
$query="select count(*) as total2 from voting Where ca_id=2";
$result = mysql_query($query);
$row2 = mysql_fetch_assoc($result);
echo"$row2[total2]<br>";
$query="select count(*) as total3 from voting Where ca_id=3";
$result = mysql_query($query);
$row3 = mysql_fetch_assoc($result);
echo"$row3[total3]<br>";
$query="select count(*) as total4 from voting Where ca_id=5";
$result = mysql_query($query);
$row4 = mysql_fetch_assoc($result);
echo"$row4[total4]<br>";
?>
[請不要在新代碼中使用'mysql_ *'函數](http://bit.ly/phpmsql)。他們不再被維護[並被正式棄用](https://wiki.php.net/rfc/mysql_deprecation)。看到[紅框](http://j.mp/Te9zIL)?學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。如果你選擇PDO,[這裏是一個很好的教程](http://j.mp/PoWehJ)。 –
如果您設置[SQL小提琴](http://sqlfiddle.com/) –
將您的值轉儲到數組並使用asort()或arsort() – Dave