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? Link to comment https://forums.phpfreaks.com/topic/197736-mysql-query-to-find-results-not-in-database/ 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; } } Link to comment https://forums.phpfreaks.com/topic/197736-mysql-query-to-find-results-not-in-database/#findComment-1037723 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); } } Link to comment https://forums.phpfreaks.com/topic/197736-mysql-query-to-find-results-not-in-database/#findComment-1037738 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.