Jump to content

[SOLVED] what does this mean?


onenonly

Recommended Posts

    $query = "SELECT name FROM ".$type." WHERE name='".$name."'";

    $results = mysql_query($query);

 

    if ($results){

 

 

what does

if ($results){

mean?

 

does it mean if it find name='".$name."'"; it true?

 

or

 

does it mean if no error even if dont find anything true?

 

It means $results !== FALSE, i.e. whether $results contains any data or not. It does not necessarily mean that $results is true.

It means if the query worked properly and added the boolean value true to the variable $results then php should execute the code in the block of { } braces.

 

If it returned a false value to $results then it will skip the code in the braces and continue after the closing brace.

error_reporting(E_ALL);
     $query = "SELECT name FROM " . $type . " WHERE name='" . $name . "'";
     $results = mysql_query($query)or trigger_error(mysql_error());
// That will give you an error reading if the query fails
     $num     = mysql_num_rows($results);

     if ($num > 0)
     {
         $row = mysql_fetch_row($results);

      }
      else
      {
         echo 'No results returned.';
      }

$result = mysql_query("SELECT......");

 

if ($result)

{

    echo 'Your query was successfull!';

}

else

{

    echo 'There was an error with your query!';

}

 

/*

This has nothing to do with how many rows there were found in the DB. This IF statement checks simply if the query syntex was correct.

*/

 

if ( mysql_num_rows( $result ) > 0 )

{

  // THIS shows what happens if rows exist...

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.