php - Rate system warning mysql_fetch_assoc? -
hi i'm kind of beginner , not know how solve problem. i'm trying create rate system. got done there problem , not know how proceed. assistance thank you.
here's code:
<?php $query = mysql_query("select * hry"); while($data = mysql_fetch_assoc($query)){ $rate_db[] = $data; $sum_rates[] = $data['rate']; } if(@count($rate_db)){ $rate_times = count($rate_db); $sum_rates = array_sum($sum_rates); $rate_value = $sum_rates/$rate_times; $rate_bg = (($rate_value)/5)*100; }else{ $rate_times = 0; $rate_value = 0; $rate_bg = 0; } ?>
here's error:
warning: mysql_fetch_assoc () expects parameter 1 resource, boolean given in /data/web/virtuals/88892/virtual/www/domains/viveregames.cz/pohledy/clanek.phtml on line 28
error means query failed.
because when query fails, mysql_query() returns false , false, think know, boolean..
well, using mysql syntax deprecated.
i suggest use pdo or mysqli.
also don't see connections database...
if aren't connected db, mysql_query returns false.
then, code shown completed? or missing things connection, select db , others?
if answer question yes then:
add these simple code lines before actual code:
$conn = mysql_connect('localhost', 'username', 'password'); if (!$conn) { die ('error while attempting connection db: ' . mysql_error()); } $db_selected = mysql_select_db('test', $conn); if (!$db_selected) { die ("error while selecting db: " . mysql_error()); }
if answer question no, please edit post adding code lines.
Comments
Post a Comment