1

i have a problem with a query in a php file. I have a query that retrieves an e-mail address, it works about right, but when it sends the email, the address is added twice.

SELECT email FROM jos_users WHERE id=$i

$i is a number that auto increments.

i have a for to check each user id to see if a email should be sent.

Any ideas?

thanks, Sebastian

2
  • 2
    Can you post the code in the file... Describing it is a lot less helpful than showing it... Commented Aug 20, 2010 at 14:08
  • 3
    The query isn't the issue. How are you iterating through the results? Commented Aug 20, 2010 at 14:09

1 Answer 1

2

If your list of ids is not too long, you could use something like this:

SELECT DISTINCT email FROM jos_users WHERE id IN (5, 18, 24, ...);

If you get a packet too long error, you can either increase the packet size, use a temporary table or keep track of the emails in your PHP application. Here is an example using temporary tables:

CREATE TEMPORARY TABLE tmp (id INT);
/* insert first 50 values (or 100, or 1000, whichever fits into your packet size)*/
INSERT INTO tmp (id) VALUES (5), (18), (24) ...;
/* insert next 50 values */
INSERT INTO tmp (id) VALUES (105), (118), (124) ...;
/* more inserts until you have a temporary table containing all ids */
INSERT INTO tmp ...
INSERT INTO tmp ...
/* select */
SELECT DISTINCT email FROM jos_users INNER JOIN tmp USING (id);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.