tomtimms Posted March 30, 2010 Share Posted March 30, 2010 I am trying to do a search to my MYSQL DB and having an issue displaying the results that were not found in my query. I have a table full of names and I am doing a search against it to find the names that are found and not found. I want to return all the names that were found in one list then all the names that were not found in another list. This is what I have so far, I am able to return all the names that were found but a little confused when it comes to displaying the ones that were not. $trimmed_up = explode(",", $trimmed); $query = "select * from site_keywords WHERE keyword IN('" . join("','", $trimmed_up) ."') ORDER BY id"; $result = mysql_query($query) or die("Couldn't execute query"); // begin to show results set $count = 1 + $s; while ($row = mysql_fetch_array($result)) { $title = $row["name"]; echo "$title<br/>"; $count++; } Quote Link to comment Share on other sites More sharing options...
runnerjp Posted March 30, 2010 Share Posted March 30, 2010 hummm... I take it you are using $_POST to search for users.... I would compare the post with the results from database... Take away those that match leaving you to echo those that are not... if($_POST != $array) { //show name } and stick that in a loop Quote Link to comment Share on other sites More sharing options...
tomtimms Posted March 30, 2010 Author Share Posted March 30, 2010 I am using the "GET" method and I can't seem to do a comparision. I have also tried the array_diff function as well...anyone have a clue on this? Quote Link to comment Share on other sites More sharing options...
runnerjp Posted March 30, 2010 Share Posted March 30, 2010 can you display the code your using for the search? Quote Link to comment Share on other sites More sharing options...
tomtimms Posted March 30, 2010 Author Share Posted March 30, 2010 <form id="htmlForm" action="feed_search_submit.php" method="get"> <input type="text" name="q" /> <input type="submit" name="Submit" value="Search" /> *(multiple search seperate with a comma) </form> then my php file $var = @$_GET['q']; $trimmed = trim($var); Quote Link to comment Share on other sites More sharing options...
tomtimms Posted March 30, 2010 Author Share Posted March 30, 2010 This topic can be closed, I was able to figure it out. Quote Link to comment Share on other sites More sharing options...
tomtimms Posted March 31, 2010 Author Share Posted March 31, 2010 I am reopening this as I am still having issues. I decided to do a comparision between my search input and the results from my query. So i did function getCompare($trimmed_up) { $query = "select * from site_keywords WHERE keyword IN('" . join("','", $trimmed_up) ."') AND status ='1' AND sid ='3' ORDER BY id"; $results = mysql_query($query); $array = mysql_fetch_assoc($results); return $array; } $all = getCompare($trimmed_up); $array1 = $all; $array2 = $trimmed_up; $compare = array_diff($array2,$array1); print_r($compare); however when I do a search for a keyword it shows up in both found and not found. Anyone else know how to get the results of a query that were not found? 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.