Skip to content Skip to sidebar Skip to footer

Display Error Message If Value Not Found Mysql

Hi i have done research on this topic i did come across a few solutions, although i wasn't able to implement them to my code because i am a beginner to this. My question is basical

Solution 1:

Use mysql_num_rows()

if(mysql_num_rows($rs) > 0) {
  // got records
}
else {
  // no records found
}

Note:

Don't use mysql_* family functions because they are going to deprecated. Start to look into mysqli or pdo


Solution 2:

$result = mysql_fetch_array($rs)
if($result)

...


Solution 3:

This usage if(count($result > 0)) is wrong. mysql_fetch_row always returns FALSE when there is no result. Please see: http://php.net/manual/en/function.mysql-fetch-array.php

You should use sometime like that

    <?php
        $results = mysql_fetch_array($rs);
        if ( $results === FALSE )
        {
             echo "No result";
        }
        else
        {
             foreach($results as $item)
             {
                     ...

             }
        }
    ?>

Post a Comment for "Display Error Message If Value Not Found Mysql"