RE: [PHP] Bizarre SQl, if issue....

From: Date: Tue, 29 Jul 2003 17:41:54 +0000
Subject: RE: [PHP] Bizarre SQl, if issue....
Groups: php.general 
Request: Send a blank email to php-general+get-157348@lists.php.net to get a copy of this message
[snip] Here's the SQL - I tested it via command line and it comes back empty set. SELECT ID FROM tblItems WHERE number = $place > > [snip] > $person = mysql_query("Some Statement Here"); > > if (!$person || $person == 0 || $person == '' || $person == '0') { > $result = > 1; } > else { $result = 4; } > > If the SQL statement returns an empty set, shouldn't $result be equal to > 1? > Instead, I'm getting $result = 4. > [/snip] > > Actually I think we need to see the query == "Some Statement Here". > $person in this case is either TRUE or FALSE [snip] So ... $person = mysql_query("SELECT ID FROM tblItems WHERE number = $place"); $person IS TRUE because query executed (the OR statements do not count as $person can only be TRUE or FALSE, so you can drop the OR's); if(!$person){ // tests to see if person IS FALSE $result = 1; } else { $result = 4; } $result will be 4 If you do this; if($person){ // tests to see if person IS TRUE $result = 1; } else { $result = 4; } $result would be 1 Now, if you used mysql_num_rows($person) $thecount = mysql_num_rows($person); if($thecount == 0){ // tests for zero $result = 1; } else { $result = 4; } $result will be 1 if(!$thecount == 0){ // tests for other than zero $result = 1; } else { $result = 4; } $result will be 4 HTH

« previous php.general (#157348) next »