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?

 

Link to comment
Share on other sites

    $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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.';
      }

Link to comment
Share on other sites

$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...

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.