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: orders@online.com");

 

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

 

 

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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