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

?>

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.