tomtimms Posted April 6, 2010 Share Posted April 6, 2010 I need to have query that will look against my database and then return all the values that were NOT found. A user searches for the names Greg, Steve, Ben, Joe and the database only has Greg and Steve. I need to then return the values of Ben and Joe. Anyone know what would be the best method to do this as? Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted April 6, 2010 Share Posted April 6, 2010 something along these lines $names=array("Ben","Tom","George"); foreach($names as $name) { $result=mysql_query("select idfield from yourtable where namefield='".mysql_real_escape_string($name)."'"); if(mysql_num_rows($result))==0) { $names_not_in_database[]=$name; } } Quote Link to comment Share on other sites More sharing options...
tomtimms Posted April 6, 2010 Author Share Posted April 6, 2010 Thanks, however I am having an issue getting my form data to an array. I have a form field that accepts the names seperated by comma's. So if you search it would go Ben,Tom,George. Here is what I have $var = @$_GET['q']; $trimmed = trim($var); $trimmed_up = explode(",", $trimmed); foreach($trimmed_up as $name) { $result=mysql_query("select keyword from site_keywords where keyword='".mysql_real_escape_string($name)."'"); if(mysql_num_rows($result)==0) { $names_not_in_database[]=$name; print_r($names_not_in_database); } } 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.