Image

Imagespacefem wrote in Imagephp

comparing lists and tables

let's say I have a list of 500 animals that someone just gave me. I also have a database table of 500 animals. what's the fastest way to figure out which animals from the list are also in the database?

ideas...

do a SELECT statement with each animal in the list. this seems a bit intense.

foreach($list_of_animals as $animal) {
$sql = "SELECT id FROM animals WHERE description = $animal"
// if there's a rowcount, it exists
}

pull all the records from the database, and do a loop...

foreach($list_of_animals as $animal) {
if (isset($sqlrow[$animal])) {
// Animal exists
}
}

OR do some temporary table thing, with an inner join? but I might have to do this hundreds of times a day with lots of people's lists so I'm not sure if temporary tables are resource-intensive.