Web Analytics Made Easy -
StatCounter Check to see if Results from Query Exist - CodingForum

Announcement

Collapse
No announcement yet.

Check to see if Results from Query Exist

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Check to see if Results from Query Exist

    Hi

    In my php page I query the database - if there are no results I get a host of errors, however if there are results it prints them fine.

    How can I test to see if the query produced no rows so that I can put a friendly message up?

    Thanks

  • #2
    Sorted

    $numrows = mysql_num_rows($result);
    if ($numrows == 0) {
    echo '<br>'."No data returned";
    exit;
    }

    Comment


    • #3
      just do a simple if statement... to check if there is a result set... then inside that if put all the code that requires that there is a result set.

      if($result) {

      insert code here that requires that the database had something in it

      }

      Comment


      • #4
        phoztech,

        checking the number of returned rows with mysql_num_rows is the only option.

        $result wil only be False if the query was incorrect, so incorrect sql-syntax. Not if it does not return any records.
        http://www.php.net/manual/en/function.mysql-query.php
        Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

        Comment


        • #5
          sorry.. you are correct... I have only messed around with mysql/php for a few months...

          Comment

          Working...
          X