bford21 Posted July 12, 2010 Share Posted July 12, 2010 I am in the process of creating a basic ratings system and I am running into some trouble. To me this code makes perfect sense but for some reason it isn't working. I think it has something to do with the way MySQL handles zeros or something because if I change $rating = 1 and change tut_rating to 1 in my database it works fine. Thanks in advance. $qry = "SELECT tut_rating FROM html_tuts WHERE tut_id=$tut_id"; $rating = mysql_query($qry); if($rating = 0.00){ echo "<img src='Images/3.5.gif' width='70' height='18'>"; } else{ echo "error"; } Link to comment https://forums.phpfreaks.com/topic/207533-simple-php-and-mysql-syntax-trouble/ Share on other sites More sharing options...
marcus Posted July 12, 2010 Share Posted July 12, 2010 <?php $sql = "SELECT tut_rating FROM `html_tuts` WHERE `tut_id` = '".$tut_id."'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) > 0){ $row = mysql_fetch_assoc($res); if($row['rating'] == '0.00'){ echo "that img"; }else { echo "error"; } }else { echo "invalid tutorial id"; } ?> Link to comment https://forums.phpfreaks.com/topic/207533-simple-php-and-mysql-syntax-trouble/#findComment-1085028 Share on other sites More sharing options...
BillyBoB Posted July 12, 2010 Share Posted July 12, 2010 I would think something like this: $qry = "SELECT `tut_rating` FROM `html_tuts` WHERE `tut_id`='$tut_id'"; $rating = mysql_query($qry); if($rating['tut_rating'] == '0.00'){ echo "<img src='Images/3.5.gif' width='70' height='18'>"; } else{ echo "error"; } Link to comment https://forums.phpfreaks.com/topic/207533-simple-php-and-mysql-syntax-trouble/#findComment-1085041 Share on other sites More sharing options...
bford21 Posted July 12, 2010 Author Share Posted July 12, 2010 Thanks guys. I knew it would be something simple. My brain is just about fried right now. Link to comment https://forums.phpfreaks.com/topic/207533-simple-php-and-mysql-syntax-trouble/#findComment-1085062 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.