SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

  2. #2
    SitePoint Addict Mal Curtis's Avatar
    Join Date
    Jul 2009
    Location
    New Zealand
    Posts
    327
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    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).
    PHP Code:
    $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.


  3. #3
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  4. #4
    SitePoint Addict Mal Curtis's Avatar
    Join Date
    Jul 2009
    Location
    New Zealand
    Posts
    327
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    No prob, let us know if you have any more problems.

    'Us' being 'Me'.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •