<?php
$totalvotes = ("SELECT COUNT(*) AS total FROM voting WHERE votes >= 0 ");
$totalvotesresults = mysql_query( $totalvotes )
or die( "Could not get total votes " .mysql_error() );
$data = mysql_fetch_array( $totalvotesresults );
echo "<div>Total number of votes is ". $data['votes'] ."</div>\n";;
?>
答案 0 :(得分:4)
您调用COUNT(*)
查询total
的结果,但在PHP中使用votes
:
echo "<div>Total number of votes is ". $data['votes'] ."</div>\n";
应该是:
echo "<div>Total number of votes is ". $data['total'] ."</div>\n";
Please, don't use mysql_*
functions in new code。它们不再被维护and are officially deprecated。请参阅red box?转而了解prepared statements,并使用PDO或MySQLi - this article将帮助您确定哪个。如果您选择PDO here is a good tutorial。