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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to exit if query does not return records?

Status
Not open for further replies.

keith23

Technical User
May 26, 2005
97
NL
Hi all . I wonder how i check if the bold query is returning no record and if no record returned the script display the following massage and the rest of script does not execute at all. I be happy if an expert show me how.Thanks


Code:
You have no PlayLists. You Must create at least one PlayList to add songs to it, Please click here to Create a PlayList


Code:
......
[B]$query2 = "select * from playlists where user_id='$username'"; [/B] //using user ID to get his playlist names
$result2 = mysql_query($query2) or die("Error with MySQL Statement! ".mysql_error()."<br>\nThe query was ".$query2);

//this line for dropdownbox
$option = "";


while($row2 = mysql_fetch_assoc($result2))
{

//This 2 line for drop downbox
extract ($row2);
    $option .= "<option value=\"$playlistname\">$playlistname</option>\r\n";

}    



?>
..... html and some php code later
......
 
Not sure of the syntax in PHP (Perl programmer) but you need the check for 'rows'.
This var returns the number of matching records.
It will return 0 if there are no matches.

Keith
 
Code:
if (mysql_num_rows($result2) == 0)
{
  die ('Query returned zero rows.')
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top