Jump to content

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>";
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.