Jump to content

Return Results Not Found In A Query


tomtimms

Recommended Posts

I am trying to do a search against my mysql database for names that are "NOT" found.  I have a search form that is submitted and I would like to return the names that were not found in the database.  Of course I am able to retrieve the names that are found but not the ones that are not.  Anyone know the best approach to this?  I was thinking to run a comparison of my query to the search variable however I want to know if there is an easier way.  Thanks to anyone who an assist. 

Link to comment
https://forums.phpfreaks.com/topic/197190-return-results-not-found-in-a-query/
Share on other sites

okay,

as this is in the PHP section and not the SQL one  :)

try this logic find all items in the database and store them in an array and then use arraydiff to generate a new array of unfound items

 

try this untested script (update table and field of course)

<?php
$findme = array("One","Two","Three","Four");
$query = sprintf("SELECT field FROM table WHERE field in (%s)",implode(",", $findme));
$result = mysql_query($query);
$found = array();
while($row = mysql_fetch_assoc($result)){
    $found[] = $row['field'];
}
$notFound = array_diff($findme, $found);
echo "<pre>";var_dump($notFound);echo "</pre>";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.