繁体   English   中英

试图计算投票表中的所有选票,但在第153行出现错误

[英]trying to count all votes from voting table but I get an error on line 153

致命错误:无法在第153行的/home/students/gar0349/public_html/project2voting.php中将stdClass类型的对象用作数组

<?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_object( $totalvotesresults );
echo "<div>Total number of votes is ". $data['total'] ."</div>\n";;
?>
$data = mysql_fetch_object( $totalvotesresults );

您正在获取作为对象,因此您需要使用as

$data->total;


echo "<div>Total number of votes is ". $data->total ."</div>\n";;

$data是一个对象,而不是数组。
尝试:

echo "<div>Total number of votes is ". $data->total ."</div>\n";
    <?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_object( $totalvotesresults );
echo "<div>Total number of votes is ". $data->total ."</div>\n";
?>

从第一行查询中删除第一个托架..和aslo

    echo "<div>Total number of votes is ". $data->total ."</div>\n";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM