您需要GROUP BY和COUNT():
SELECT image, COUNT(*) as Votes FROM january GROUP BY image
这将返回两列:1表示图像,1表示该图像的投票数:
image Votes
001.jpg 1
002.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>";
}