[thelist] insert if select fails to find element
Alex Beston
alex at deltatraffic.co.uk
Thu Nov 17 00:53:01 CST 2005
hi List
heres my code i want to optimise:
// $dictionary has 100,000 elements
// open link
while($word = array_pop($dictionary)){
// check we dont have this word already in our store
$query_string = "SELECT word FROM word_list WHERE word = '$word'";
$result = mysql_query ($query_string) or die(mysql_error());
if(!mysql_num_rows($result)){
$query = "INSERT into word_list(word) VALUES ('$word')";
mysql_query($query) or die(mysql_error()); ;
$counter++;
}
}
// close link
is there a way of putting all the work on the sql - something like
""INSERT into word_list(word) VALUES ('$word')" IF ('$word') NOT EXISTS";
something like that. so have one query rather than two.
i've seen this before but i cant remember the syntax...
ta
Alex
--
-_-_-_-_-_-_-_-_-_-_-
deltatraffic.co.uk
Current Location:
KL, Malaysia
_-_-_-_-_-_-_-_-_-_-_
More information about the thelist
mailing list