Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts

    How do I sort ot these "while" loops ?

    What is the best way to write the while loops
    for this:

    I have a MySQL table of clients that I want to send a series of 5 emails
    after they sign up.

    The clients are in 2 groups and they'll get two different sets of emails.

    So my table is like this:

    cl_name | group | eml_cnt | email_add | other stuff ...

    Dave | A | 0 | Dave@email_add.com | other stuf
    Stev | A | 3 | Stev@email_add.com | other stuf
    John | B | 0 | John@email_add.com | other stuf
    Pete | A | 1 | Pete@email_add.com | other stuf
    Jeffe | B | 2 | Jeffe@email_add.com | other stuf
    Jacky| A | 4 | Jacky@email_add.com | other stuf

    I will run the script every 2 days and it needs to
    send:

    messageA1.txt to group A who are at count 0
    messageA2.txt to group A who are at count 1
    messageA3.txt to group A who are at count 2
    messageA4.txt to group A who are at count 3
    messageA5.txt to group A who are at count 4

    and

    messageB1.txt to group B who are at count 0
    messageB2.txt to group B who are at count 1
    messageB3.txt to group B who are at count 2
    messageB4.txt to group B who are at count 3
    messageB5.txt to group B who are at count 4

    Should I index the table ? if so with which key ?

    As the message is sent the eml_cnt field needs to be
    incremented by one.

    I am a bit lost about how to do the logic for the
    while or for loops

    So if anyone can help me out, I'd appreciate it
    Last edited by jeddi; 03-16-2009 at 12:08 PM.

  • #2
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    You need two other fields...
    Code:
    cl_name 
    group 
    eml_cnt 
    email_add
     other stuff
    datesent
    sent (with a Y or N)
    Now run a query to check if anyone was sent an email on the specified date, if not send the email and set the datesent and set the sent with Y...
    Logic for me is backwards, I always do the last thing first, I can only suggest the above.

    PHP Code:
    $boundary "------------";
    $multipartheader "Content-type: multipart/alternative; ";
    $multipartheader .= "boundary=\"".$boundary."\"";
    $textheader "Content-Type: text/plain; charset=us-ascii\n";
    $textheader .= "Content-Transfer-Encoding: 7bit";
    $htmlheader "Content-Type: text/html; charset=us-ascii\n";
    $htmlheader .= "Content-Transfer-Encoding: 7bit";
    $endmessage "--\n\n-- End --";
    $to "name@example.com";
    $subject "Subject";

    $textmessage join("",file("filetosend")); //add your text file here

    $from "From: Nice Name <name@example.com>";
    $replyto "reply-to: name@example.com";
    $header $from// set the from field in the header
    $header .= "\n"// add a line feed
    $header .= $replyto// add the reply-to header to the header
    $header .= "\n"// add a line feed
    $header .= "MIME-version: 1.0\n"//add the mime-version header
    $header .= $multipartheader;
    $header .= "\n";
    $message $boundary."\n".$textheader."\n\n";
    $message .= $textmessage."\n\n";
    $message .= "--".$boundary."\n".$htmlheader."\n\n";
    $message .= $htmlmessage."\n\n";
    $message .= "--".$boundary.$endmessage;
    mail($to$subject$message$header); // send the e-mail 
    Cheers
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #3
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Thanks for this,
    I was not too worried about sending the email out
    (although I'll bear in mind your suggestions )

    I was more concerned about ordering the database table
    correctly and stepping through it to send the correct email to the correct
    group. It's the looping logic that I need some help with

    Thanks again.

  • #4
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    I don't think I understand...
    Code:
    I sign up
    I get 5 emails
    The date gets set
    eml_cnt increments by 1
    Do this until eml_cnt = 5 now wait 2 days and send 5 emails again.
    What are the 2 days for?
    Why 5 emails?

    Cheers
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #5
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Thanks for your question,
    maybe I wasn't clear enough.

    You sign up as either group A or B (depending on which one you want)

    If you are in group A when the script is run you
    get sent messageA1.txt and your eml_cnt increments by 1

    Two days later you get messageA2.txt
    and your eml_cnt increments by 1 etc

    Meanwhile your mate signs up for group B

    Two days later you get messageA3.txt
    Your friend gets messageB1.txt

    Two days later you get messageA4.txt
    Your friend gets messageB2.txt

    Two days later you get messageA5.txt
    Your friend gets messageB3.txt

    Two days later your friend gets messageB4.txt

    Two days later your friend gets messageB5.txt


    Every two days the same script is run so the script needs to
    increment the database table and send the correct email to the correct group.

    I don't think we need to worry about the date - just send
    the emails acoording to what the client has already been sent.

    If the script is run a day late - it should not make any difference
    to what is sent out.

    Hope that helps to make it clearer what I am trying to do.
    Last edited by jeddi; 03-18-2009 at 07:59 AM.

  • #6
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts

    Thumbs up

    In that case I would go with switch statement
    PHP Code:
    switch (expression){
    case 
    0:
      
    // code to be executed if expression = 0;
      
    break;  
    case 
    1:
      
    // code to be executed if expression = 1;
      
    break;
    default:
    // code to be executed 
    // if expression is different from both 0 and 1;

    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •