onenonly Posted May 31, 2009 Share Posted May 31, 2009 $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? Quote Link to comment https://forums.phpfreaks.com/topic/160365-solved-what-does-this-mean/ Share on other sites More sharing options...
anupamsaha Posted May 31, 2009 Share Posted May 31, 2009 $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. Quote Link to comment https://forums.phpfreaks.com/topic/160365-solved-what-does-this-mean/#findComment-846245 Share on other sites More sharing options...
Andy-H Posted May 31, 2009 Share Posted May 31, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/160365-solved-what-does-this-mean/#findComment-846246 Share on other sites More sharing options...
onenonly Posted May 31, 2009 Author Share Posted May 31, 2009 so it doesnt query the data basically it mean if no error return then true Quote Link to comment https://forums.phpfreaks.com/topic/160365-solved-what-does-this-mean/#findComment-846252 Share on other sites More sharing options...
dreamwest Posted May 31, 2009 Share Posted May 31, 2009 so it doesnt query the data basically it mean if no error return then true Yes. if ($results){ //theres results from query } OR if (! $results){ //no results from query } Quote Link to comment https://forums.phpfreaks.com/topic/160365-solved-what-does-this-mean/#findComment-846253 Share on other sites More sharing options...
Andy-H Posted May 31, 2009 Share Posted May 31, 2009 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.'; } Quote Link to comment https://forums.phpfreaks.com/topic/160365-solved-what-does-this-mean/#findComment-846254 Share on other sites More sharing options...
onenonly Posted May 31, 2009 Author Share Posted May 31, 2009 thx andy dats what i been trying to find!!! thanks yall!!!!! BIG HELP THUMBS UP!!! Quote Link to comment https://forums.phpfreaks.com/topic/160365-solved-what-does-this-mean/#findComment-846268 Share on other sites More sharing options...
nick73 Posted May 31, 2009 Share Posted May 31, 2009 $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... } Quote Link to comment https://forums.phpfreaks.com/topic/160365-solved-what-does-this-mean/#findComment-846276 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.