编辑
好的,我已经修正了我现在遇到的任何错误,但是我唯一想要理解的就是为什么我现在没有看到屏幕上出现的派对的名字!
<?php
$id = $_GET['election'];
$result = mysql_query(
sprintf("
SELECT votes.party, COUNT(votes.vote_id)
FROM votes
WHERE election_id = %d
GROUP BY election_id, votes.party
ORDER BY COUNT(votes.vote_id) DESC",
mysql_real_escape_string($id)
)
);
// change is here
$votes = false;
$winners = array();
while ( ($row = mysql_fetch_row($result) ) && ( ($votes==false) || ($row['vote_count']===$votes) ) ) {
$winners[] = $row['party'];
$votes = $row['vote_count'];
}
echo '<hr><h3>'.'Results</h3><hr>'.'<h4>'.implode(' and ', $winners).' won with '.$votes.'</h4>';
?>我在银幕上得到的只是“并赢得了”。我不会让当事人的名字出现的!有人知道吗?
发布于 2012-03-23 22:10:29
他们可能是2名胜利者,但也是3,4名.谁知道呢。
下面是显示所有真正赢家的通用代码:
// no change here
$id = $_GET['election'];
$result = mysql_query(
sprintf("
SELECT votes.party, COUNT(votes.vote_id) AS vote_count
FROM votes
WHERE election_id = %d
GROUP BY election_id, votes.party
ORDER BY COUNT(votes.vote_id) DESC",
mysql_real_escape_string($id)
)
);
// change is here
$votes = false;
$winners = array();
while ( ($row = mysql_fetch_assoc($result) ) && ( ($votes==false) || ($row['vote_count']===$votes) ) ) {
$winners[] = $row['party'];// was missing the $ before row['party'];
$votes = $row['vote_count'];
}
echo '<hr><h3>'.'Results</h3><hr>'.'<h4>'.implode(' and ', $winners).' won with '.$votes.'</h4>';https://stackoverflow.com/questions/9846883
复制相似问题