I have this problem with sending 200 000 times the query "SELECT * FROM emails WHERE title = '".$el."'" to check if the email already exist in the DB. It looks like this : foreach ($emails as $el) { $query = "SELECT * FROM emails WHERE title = '".$el."'"; here goes the check... } but if i put a counter in "foreach" without the $query, it goes through all elemenets, unfortunately if I send a query every time it can't reach the end of the cycle... with 100 000 emails there is no problem... what am i doing wrong?
Are you doing this before adding them to your database? You could do a conditional insert if that is the case and the emails in there wont get added. You could also create a unique index on the email column which would prevent duplicates.
What error do you get? Is it simply a case of PHP exceeding the time limit? Use set_time_limit(0); to prevent that. Otherwise, you may want to change your query so that you process the emails in chunks of 100 and use WHERE title IN (' . implode(',', $email_chunk) . ')'; (You would have to already add " and mysql_real_escape_string before you do that though.)
PHP exceeding the time limit... that was the problem! and set_time_limit(0); made it work thanks a lot!