php_begins Posted December 8, 2011 Share Posted December 8, 2011 i retrieving an adid from $_GET which is also a value retireved from a database. $this_adid=$_GET['adid']; if(empty($this_adid)) { $get_ad_id = mysql_query("SELECT userid FROM ads WHERE adid='$this_adid'", $con) or die("Error Getting AD ID: ".mysql_error()); while($get_ad_id_results = mysql_fetch_assoc($get_ad_id)) { $owner_id=$get_ad_id_results['userid']; } } the above query works if $this_adid returns 0 (http://www.website.com/?do=delete&adid=0&givenuserid=15773) i.e. adid is 0 in the table. But it does not work if $this_adid returns null or ntohin (http://www.website.com/?do=delete&adid=&givenuserid=15773) .i.e adid is ' ' (empty) field in the databse table.. can someone tell me why it does not check for null or empty values properly? Quote Link to comment Share on other sites More sharing options...
php_begins Posted December 8, 2011 Author Share Posted December 8, 2011 i still want to execute the query if the the adid field is empty or null. in some places adid is stored as empty(there is no value in the database table.) i still need to compare those values in the table nad execute. Right now if the adid field is empty it does not return anything.. Note: adid is not a primary key.it can be null Quote Link to comment Share on other sites More sharing options...
ohdang888 Posted December 8, 2011 Share Posted December 8, 2011 well this: " SELECT userid FROM ads WHERE adid='$this_adid' " will ALWAYS be translated as this: "SELECT userid FROM ads WHERE adid='' " because its nested within an empty caluse. Are there any records that have NOTHING in adid column? you should always try print_r on the results Quote Link to comment Share on other sites More sharing options...
php_begins Posted December 8, 2011 Author Share Posted December 8, 2011 like i said the adid field is empty in the database table in some cases.(there is no value for adid in the table even when there are userids) so i want to select userid from the ad table where adid=NULL or ' ') this would still give me the userids. But unfortunately it does not return anything..i do not know to how to check for fields tht have no value.. Quote Link to comment 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.