denoteone Posted May 29, 2009 Share Posted May 29, 2009 I am checking a database to see if a variable is in there if it is I want to do something. Am I on the right track here? the varible $row['visitor_whois'] changes because this is part of a bigger while statement. $query = "SELECT * FROM isp WHERE name = $row['visitor_whois']"; $result = mysql_query($query)or die (mysql_error()); if( $result == "true"){ } Quote Link to comment https://forums.phpfreaks.com/topic/160188-solved-if-query-returns-something-does-it-return-true/ Share on other sites More sharing options...
Ken2k7 Posted May 29, 2009 Share Posted May 29, 2009 <?php $query = "SELECT * FROM isp WHERE name = '{$row['visitor_whois']}'"; $result = mysql_query($query)or die (mysql_error()); while ($row = mysql_fetch_assoc($result)) { if( $row['column_name'] == "true" ){ } } Change column_name to the column name you want to compare the value to. But if you only want to compare it to the value true, you can use this SQL: <?php $query = "SELECT * FROM isp WHERE name = '{$row['visitor_whois']}' AND column_name = 'true'"; $result = mysql_query($query)or die (mysql_error()); while ($row = mysql_fetch_assoc($result)) { // do your stuff here } That will select all rows where name = some name and the specified column_name value is true. Quote Link to comment https://forums.phpfreaks.com/topic/160188-solved-if-query-returns-something-does-it-return-true/#findComment-845186 Share on other sites More sharing options...
kickstart Posted May 29, 2009 Share Posted May 29, 2009 Hi If nothing is returned but query has still worked then it will return true. False will be returned if there is an error. $query = "SELECT * FROM isp WHERE name = '".$row['visitor_whois']."'"; $result = mysql_query($query)or die (mysql_error()); if( mysql_fetch_array($result)) { // Some code here } or if you do not care about any data returned and just want to know some is:- $query = "SELECT * FROM isp WHERE name = '".$row['visitor_whois']."'"; $result = mysql_query($query)or die (mysql_error()); if( mysql_num_rows($result) > 0) { // Some code here } All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/160188-solved-if-query-returns-something-does-it-return-true/#findComment-845187 Share on other sites More sharing options...
denoteone Posted May 29, 2009 Author Share Posted May 29, 2009 Thanks I used kickstart's second example. Quote Link to comment https://forums.phpfreaks.com/topic/160188-solved-if-query-returns-something-does-it-return-true/#findComment-845221 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.