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. |