0
<?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";;
?>
John Conde
  • 217,595
  • 99
  • 455
  • 496

1 Answers1

4

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.

Community
  • 1
  • 1
John Conde
  • 217,595
  • 99
  • 455
  • 496