您需要GROUP BY和COUNT():
SELECt image, COUNT(*) as votes FROM january GROUP BY image
这将返回两列:1表示图像,1表示该图像的投票数:
image votes001.jpg 1002.jpg 32...
完整代码:
$db = mysql_connect("xxx", "xxx", "xxx");mysql_select_db("club",$db);$q = mysql_query("SELECT image, COUNT(*) as votes FROM january GROUP BY image");$votes = array();while ($row = mysql_fetch_assoc($q)) { $votes[$row['image']] = $row['votes'];}// $votes is an array of 'image' => 'votes'foreach($votes as $image => $count) { echo "$image: $count<br>";}


