Jump to content

Simple PHP and MySQL syntax trouble


bford21

Recommended Posts

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

<?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";
}

?>

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";
   }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.