Mailing list using MySQL / PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dariusz

    Mailing list using MySQL / PHP

    I have written a database which uses PHP to run through each ID in the
    database and then generate a persons name and address to include into the
    rest of the PHP to send an email out.

    But as people have deleted or updated their details on this mailing list, I
    now have "holes" in database. Ordinarily not a problem, but the code I've
    written starts at ID 1 and after sending an email increments to the next
    ID. But when it encounters a now vacant ID, it sends an error email to me
    associated with that now blank ID row of data.

    How can I change my code that will increment through all the results in
    turn, but not give me these error emails when people have amended the
    database?

    Dariusz
  • michel

    #2
    Re: Mailing list using MySQL / PHP

    Why are you looping through the numbers?

    Try just getting your excisting rows in sequence, ignoring the ID numbers
    (you can read them if you need them, but shouldn't use them as criteria in
    your SELECT statement)

    Regards,

    Michel



    "Dariusz" <ng@lycaus.plus YOURSHIT.com> wrote in message
    news:KHcyc.1352 6$NK4.1984990@s tones.force9.ne t...[color=blue]
    > I have written a database which uses PHP to run through each ID in the
    > database and then generate a persons name and address to include into the
    > rest of the PHP to send an email out.
    >
    > But as people have deleted or updated their details on this mailing list,[/color]
    I[color=blue]
    > now have "holes" in database. Ordinarily not a problem, but the code I've
    > written starts at ID 1 and after sending an email increments to the next
    > ID. But when it encounters a now vacant ID, it sends an error email to me
    > associated with that now blank ID row of data.
    >
    > How can I change my code that will increment through all the results in
    > turn, but not give me these error emails when people have amended the
    > database?
    >
    > Dariusz[/color]


    Comment

    • Pedro Graca

      #3
      Re: Mailing list using MySQL / PHP

      Dariusz wrote:[color=blue]
      > I have written a database which uses PHP to run through each ID in the
      > database and then generate a persons name and address to include into the
      > rest of the PHP to send an email out.
      >
      > But as people have deleted or updated their details on this mailing list, I
      > now have "holes" in database. Ordinarily not a problem, but the code I've
      > written starts at ID 1 and after sending an email increments to the next
      > ID. But when it encounters a now vacant ID, it sends an error email to me
      > associated with that now blank ID row of data.
      >
      > How can I change my code that will increment through all the results in
      > turn, but not give me these error emails when people have amended the
      > database?
      >
      > Dariusz[/color]

      Instead of

      $conn = mysql_connect(D B_HOST, DB_USER, DB_PASS) or die();
      loop() {
      $sql = 'select c1, c2, c3 from table where id=' . $id;
      $res = mysql_query($sq l) or die();
      $row = mysql_fetch_row ($res);
      mail($res[0], $res[1], $res[2]);
      mysql_free_resu lt($res) or die();
      }
      mysql_close() or die();

      do

      $conn = mysql_connect(D B_HOST, DB_USER, DB_PASS) or die();
      $sql = 'select c1, c2, c3 from table order by id';
      $res = mysql_query($sq l) or die();
      while ($row = mysql_fetch_row ($res)) {
      mail($res[0], $res[1], $res[2]);
      }
      mysql_free_resu lt($res) or die();
      mysql_close() or die();



      Disclaimer: both snippets were typed directly into the editor, and I
      wasn't concentrating on making them right.

      --
      USENET would be a better place if everybody read: | to email me: use |
      http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
      http://www.netmeister.org/news/learn2quote2.html | header, textonly |
      http://www.expita.com/nomime.html | no attachments. |

      Comment

      Working...