Send To ALL ID'd In Column

Discussion in 'MySQL' started by timallard, May 12, 2009.

  1. #1
    Hello,

    I am using php.

    Im just finishing up an alert system in a tool im building and i am trying to send an alert to ALL user id's in a column.

    I have successfully got it to work with just sending to one, but how can i have it send to all? do i need to throw the SQL into a loop running through all users? or is that way over complicating the query?

    if so, how?

    Thank you!
     
    timallard, May 12, 2009 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    What method are you using to send to a single user? Is this like a php mail function or some other application level alert?
     
    jestep, May 12, 2009 IP
  3. timallard

    timallard Well-Known Member

    Messages:
    1,634
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    158
    #3
    Hey Jestep, your like my personal PHP/ MYSQL book lately, thanks for the attention.


    Its nothing crazy just yet, its basically a simple php form, when on submission, inserts an alertid, userid, headline and message into an alerts table.

    there is a dropdown on the send alert page where you can choose from all users in the users table, simly by choosing the select option you can send it to one person..

    There is no php mail function implimented yet (soon) right now, it just displays in the alerts area of the tool, you can click on the headline and it shows the message.

    if an admin wanted to send to "all" thats where im stuck.

    so nothing fancy here goin on really..
     
    timallard, May 12, 2009 IP
  4. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #4
    You would basically write a query to pull all the members out of the DB.

    If you are adding to another table you can use a nested query like this to enter an entry for every user.

    INSERT INTO alerts (`id`,`alert_text`) SELECT (`id`, 'ALERT TO ENTER') FROM user_table;

    If you need to get a list of them for emails, something like this would be appropriate.

    SELECT name, email FROM members WHERE email_active = 1 AND allow_notice = 1;

    Then loop through it and send an email each time.

    There are two ways to send a mass-email, and you may want to test each method to determine which works best. The first is to send a single email to each user, the second is to send a bulk email to each user by putting all of their addresses in the BCC field.

    When sending mass emails, there's always the chance of getting your IP / server being labeled as spam. If you get added to any large blacklist, it gets extremely difficult to get anything delivered, so definitely be sure to only send to users that have previously indicated that they allow notification, or whatever other emails you will be sending them.
     
    jestep, May 12, 2009 IP
  5. timallard

    timallard Well-Known Member

    Messages:
    1,634
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    158
    #5
    Thank you for this thorough explanation! I'm trying to implement now.
    Its funny, im asking so many questions, but you wont believe what I am learning in a short amount of time!! I appreciate it.

    PM me your paypal and i can give you a little something for your time if you would like.
     
    timallard, May 12, 2009 IP