Using SQL result to send different emails via PHP

Morning All,

This is my first post, so be kind to me.
I am having a little bit of trouble with a solution I am doing and wondering if I could get some help. I’m not sure if this is for the SQL area or PHP so let me know if I have posted it in the wrong place!

I am creating a solution where you can order items. Once the order is confirmed an email gets sent in two ways:

  1. If any items require approval an email gets sent to an TL’s email.
  2. If all items do not require approval, it gets sent for processing in the warehouse.

I am assuming this requires an “if statement” of my SQL result???

for eg.
$sql=“SELECT ordering.status, ordering.emplNum, ordering.description
FROM ordering
LEFT JOIN primaryOrder ON ordering.orderNumber = primaryOrder.orderId
WHERE primaryOrder.orderId =”.$primaryOrderId.“”;
$result=es_query($sql);
$row=mysql_fetch_array($result);

I am a newbie at this, so I’m hoping for some help here, how do I word the ‘if statement’ so that it emails correctly?

Thanks for your help.

How do you know which items need to be approved?

Sounds like you need to select all items from the order, loop through and then check if any of them have the approval value. A basic example of this might look like this (this assumes the items have a column in the database that states whether it requires approval).


$sql="SELECT ordering.approval
FROM ordering
LEFT JOIN primaryOrder ON ordering.orderNumber = primaryOrder.orderId
WHERE primaryOrder.orderId =".$primaryOrderId."";
$result=es_query($sql);
$requiresapproval = false;
while($row=mysql_fetch_array($result))
{
 if($row['approval'] == 1) $requiresapproval = true;
}

if($requiresapproval){
   // send the requires approval email here
}else{
   // send the warehouse email here.
}

Thanks for the reply Mal.
There is another table that I reference, in an earlier sql statement that I haven’t provided above, where the stock items ordered have a status of “requires approval” or “not required”.
It might be a bit too long winded to explain in here!

I didn’t think of doing a while loop. Again, I’m a newbie!

Thank You for the help :slight_smile:

No prob, let us know if you have any more problems.

‘Us’ being ‘Me’.