Results 1 to 2 of 2

Thread: How to exit if query does not return records?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Arrow How to exit if query does not return records?

    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:
    ......
    $query2 = "select * from playlists where user_id='$username'";  //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
    ......

  2. #2
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: How to exit if query does not return records?

    PHP Code:
    $query2 "select * from playlists where user_id='$username'";  //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 "";

    if(
    mysql_num_rows($result2) == 0){
    echo 
    'errormsg';
    }
    else{
    while(
    $row2 mysql_fetch_assoc($result2))
    {

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



    sumtin like that.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width