<?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";;
?>
You call the result of your COUNT(*)
query total
but use votes
in your PHP:
echo "<div>Total number of votes is ". $data['votes'] ."</div>\n";
should be:
echo "<div>Total number of votes is ". $data['total'] ."</div>\n";
Please, don't use mysql_*
functions in new code . They are no longer maintained and are officially deprecated . See the red box ? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.