Page 1 of 1

Advice on checking an array against a database, please.

Posted: Fri Jun 25, 2004 4:01 am
by mendingo
I have an array, array1 of words.

I want to return an array, array2 that contains all the words from array1 that do not exist in a given column (col1) of a given table (Table1).

What's the most efficient way of doing this?

Posted: Fri Jun 25, 2004 8:13 am
by evanz
can use array_diff($ar1,$ar2).

Posted: Fri Jun 25, 2004 10:40 am
by Weirdan

Code: Select all

$array1 = array('some','words','here');
foreach($array1 as $key => $value) 
  $array1[$key] = mysql_escape_string($value);
$res = mysql_query('select word from sometable where word not in("' . implode('","', $array1) . '")');
while( list($word) = mysql_fetch_row($res) ) {
  // do something to word
}