Posted by Toby Inkster on 12/12/06 07:01
Rik wrote:
> Indeed, or possibly check it first:
> $searchstring = md5(//something);
> $result = mysql_query("SELECT `textmd5` FROM `logs_full` WHERE `textmd5` =
> '{$searchstring}'");
> if(mysql_num_rows($result) < 1){
> //not in table logic..
> } else {
> //is in table logic..
> }
As the OP said, he needs to check "hundreds of thousands" of md5 strings
-- using an SQL call for each one will slow him down.
My advice would be to keep doing roughly what you're already doing, but
speed up your array search.
To speed up your search, make sure your array is sorted in alphabetical
order. You can do this using your initial SQL query:
SELECT textmd5 FROM logs_full ORDER BY textmd5;
(Note: the query will speed up by specifying the exact column you need to
select; not '*'.)
You can then use a binary search function[1] instead of in_array() to
check that a value exists in your array.
____
1. Such as...
http://www.rci.rutgers.edu/~jfulton/binary_search/binary_search.inc
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
[Back to original message]
|