radagast Posted June 18, 2012 Share Posted June 18, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/264364-updating-and-emailing-all-rows-in-a-loop/ Share on other sites More sharing options...
ShoeLace1291 Posted June 18, 2012 Share Posted June 18, 2012 Are you sure that there is more than one row being selected? Quote Link to comment https://forums.phpfreaks.com/topic/264364-updating-and-emailing-all-rows-in-a-loop/#findComment-1354794 Share on other sites More sharing options...
MaaSTaaR Posted June 18, 2012 Share Posted June 18, 2012 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); Quote Link to comment https://forums.phpfreaks.com/topic/264364-updating-and-emailing-all-rows-in-a-loop/#findComment-1354796 Share on other sites More sharing options...
radagast Posted June 18, 2012 Author Share Posted June 18, 2012 Hello MaaSTaaR Yes thanks so much that did the trick Quote Link to comment https://forums.phpfreaks.com/topic/264364-updating-and-emailing-all-rows-in-a-loop/#findComment-1354814 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.