Jump to content

Updating and emailing all rows in a Loop


radagast

Recommended Posts

Good Day

 

I am have the following problem and would appreciate any help.

 

I would like to send a email as well as update orders.sent_order_confirm when the below SELECT query criteria is meet

 

$sendemail = "SELECT * FROM orders WHERE order_num IS NOT NULL AND sent_order_confirm IS NULL";

$result = mysql_query($sendemail)

or die ("Error in query: $sendemail. " . mysql_error());

// if records present

// iterate through resultset

// print title with links to edit and delete scripts

if (mysql_num_rows($result) > 0)

{

while($row = mysql_fetch_object($result))

 

 

{

$order_num = $row->order_num;

$email=$row->email;

$contactname=$row->dest_contact;

 

 

 

$formsentfrom = mail("$email",

"Your Online Order Number $order_num",

"Good Day $contactname \r\n\r\n

 

This email is just to let you know that your Order Number $order_num has been processed \r\n",

"From: [email protected]");

 

$sql = "UPDATE orders SET sent_order_confirm = 'yes' WHERE order_num = $order_num";

$result=mysql_query($sql);

}

}

 

At the moment it is only updating one row and sending one email. But If I remove the below then it will send emails to all rows.

$sql = "UPDATE orders SET sent_order_confirm = 'yes' WHERE order_num = $order_num";

$result=mysql_query($sql);

 

 

So my question is how do I get it to update all rows and send all emails within the loop.

 

All and any help will be greatly appreciated.

 

 

In these lines :

 

$sql = "UPDATE orders SET sent_order_confirm = 'yes' WHERE order_num = $order_num";
$result=mysql_query($sql);

 

Change the variable name "$result" to anything else.

 

Example :

 

 

$sql = "UPDATE orders SET sent_order_confirm = 'yes' WHERE order_num = $order_num";
$update=mysql_query($sql);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.