how to display there msg ( there is no item ) when mysql query return no data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • khalidbaloch
    New Member
    • Oct 2006
    • 61

    how to display there msg ( there is no item ) when mysql query return no data

    i want to show on page the messege that say there is currently no item when a mysql query return no record instead of blank page ..
    i hope this is not a big issue and will be resolved in first reply

    thanks for any help in advance .....
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Show the MySQL query. Don't let me quess what you're doing!

    Ronald :cool:

    Comment

    • vssp
      Contributor
      • Jul 2006
      • 268

      #3
      If (mysql_num_rows ($res)==0)
      {
      echo "No records";
      }
      else
      {
      \\Display result .

      }


      I hop this massage usfull for u

      vssp

      Comment

      • khalidbaloch
        New Member
        • Oct 2006
        • 61

        #4
        here is my sql query with php code please give an example with complete code as i am a new to php

        Code:
        <?php
        require ("dbconnect.php");
        $result = mysql_query("SELECT * FROM news_content WHERE catid='1'
         AND status='approved'") or die(mysql_error());  
        $row = mysql_fetch_array( $result );
        echo $row['news_title']." - ".$row['short_description'];"-".$row['news_details'];
        ?>

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

          #5
          Don't fool me: you are not that new to PHP and you should read what vssp wrote regarding use of mysql_num_rows( ).
          Code:
          <?php
          require ("dbconnect.php");
          $result = mysql_query("SELECT * FROM news_content WHERE catid='1'
           AND status='approved'") or die(mysql_error());  
          If (mysql_num_rows($result) == 0) {
            echo "No records";
          }
          else {
            $row = mysql_fetch_array( $result );
            echo $row['news_title']." - ".$row['short_description'];"-".$row['news_details'];
          }
          ?>
          Ronald :cool:

          Comment

          • khalidbaloch
            New Member
            • Oct 2006
            • 61

            #6
            thanx ronald it is done but no i want to use this in mysql_fetch_obj ect function in order to retrive more than one row
            i tried alot at last i succedd .i found this way to accomplish that ..
            if there is a better idea please let me know
            Code:
            <?
            $topic_id=$_GET['topic_id'];
            require 'dbconnect.php';
            $sql = "SELECT * FROM news_content  WHERE topic_id='$topicid' LIMIT 10";
            $result = mysql_query($sql);
            if (mysql_num_rows($result) ==0) { echo "no record";
            }
            else {
            while ($record = mysql_fetch_object($result)) {
            echo $row['news_title']." - ".$row['short_description'];"-".$row['news_details'];
            }
            }
            ?>

            Comment

            • khalidbaloch
              New Member
              • Oct 2006
              • 61

              #7
              sorry i have misspelled in previous post i put $row['etc'] instead of $record->etc
              so bellow is the right script ..
              Code:
              <?
              $topic_id=$_GET['topic_id'];
              require 'dbconnect.php';
              $sql = "SELECT * FROM news_content  WHERE topic_id='$topicid' LIMIT 10";
              $result = mysql_query($sql);
              if (mysql_num_rows($result) ==0) { echo "no record";
              }
              else {
              while ($record = mysql_fetch_object($result)) {
              echo $record->short_description - $record->title
              }
              }
              ?>

              Comment

              Working...