By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,746 Members | 1,924 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,746 IT Pros & Developers. It's quick & easy.

Mailing list using MySQL / PHP

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.plusYOURSHIT.com> wrote in message
news:KH*********************@stones.force9.net...
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

Jul 17 '05 #2

P: n/a
Dariusz wrote:
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


Instead of

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

do

$conn = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die();
$sql = 'select c1, c2, c3 from table order by id';
$res = mysql_query($sql) or die();
while ($row = mysql_fetch_row($res)) {
mail($res[0], $res[1], $res[2]);
}
mysql_free_result($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. |
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.