Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi all, What would be the best way

Status
Not open for further replies.

camcim

Programmer
Jan 25, 2003
20
0
0
US
Hi all,
What would be the best way to write the following query?
I have a table called movie_rating which contains two fields called movie_id and movie_rating.
If there is no row associated with the movie_id field then i want it to echo that there is no row containing the movie_id value and if it does then it should echo the movie_id value.

Any ideas?
camcim
 
Let's assume that i do know the value of $movie_id.
Eg: $movie_id = 3
 
ok, well just query for that id, and then use mysql_num_rows() like so:
Code:
$query="select * from movie_rating where movie_id=".$movie_id;
$result=mysql_query($query);
if(mysql_num_rows($result) == 0)
  echo "id not found";
else
  echo $movie_id;
you wouldnt necessarily need to retrieve both columns but if your going to use that data somewhere you might as well get it now. you could add some lines in the else block to fill an array with that data:
Code:
  $row=mysql_fetch_assoc($result);
  $rating[$movie_id]=$row["movie_rating"];
what we see depends mainly on what we're looking for.
--John Lubbock
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top