SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    292
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    part of code looping twice

    i have a code that send two emails to different people but the first mail sends the right total amount, while the message to the second email(los@yahoo.ca) adds up the total amount twice and sends it.please how can i fix it

    PHP Code:
      $body "<html><body><table border='1'>
    <tr>
    <th>Shop Name</th>
    <th>Product Name</th>
    <th>Size</th>
    <th>Color Name</th>
    <th>Quantity</th>
    <th>Price</th>
    <th>Cost</th>
    </tr>"
    ;
    $totalPrice 0;
    $pplresult mysql_query("SELECT * FROM repplac WHERE Uname = '{$_SESSION['username']}'");   
    while(
    $row mysql_fetch_assoc($pplresult)){ 
        
    $body .= "<tr>
            <td>" 
    $row['Sname'] ."</td>
            <td>" 
    $row['Pname'] ."</td>
            <td>" 
    $row['Psize'] ."</td>
            <td>" 
    $row['Pcolour'] ."</td>
            <td>" 
    $row['Pquantity'] ."</td>
            <td>" 
    $row['Price'] ."</td>
            <td>" 
    $row['Tprice'] ."</td>
            </tr>"
    ;
             
    $totalPrices += $row['Tprice'];
    }

         if(
    0.1*$totalPrices <= 50 )
        {
        
    $totalprice = (0.1*$totalPrices +  $totalPrices);
        }
        else
       {
        
    $totalprice 50 $totalPrices;
            }
    $body .= "<tr>
                <td colspan=6>Total :</td> 
                           
                <td>" 
    $totalprice ."</td>
            </tr>"
    ;

    $body .="</table></body></html>";

       
    //Send email
    $to $email
       
    $subject "YOUR ORDER LIST($orderno) FROM REACHEASY"
     
    $headers "From: donotreply@easy.co.uk\r\n"
                
    'MIME-Version: 1.0' "\r\n"
                
    'Content-type: text/html; charset=iso-8859-1' "\r\n"
                
    'Bcc:notification@easy.co.uk' "\r\n";

    mail($to,$subject,$body,$headers);

        
    //Get list to managers user
       
    $body "<html><body><table border='1'>
    <tr>
    <th>Shop Name</th>
    <th>Product Name</th>
    <th>Size</th>
    <th>Color Name</th>
    <th>Quantity</th>
    <th>weblink</th>
    <th>info</th>
    <th>Price</th>
    <th>Cost</th>
    </tr>"
    ;
    $totalPrice 0;
    $pplresult mysql_query("SELECT * FROM repplac WHERE Uname = '{$_SESSION['username']}'");   
    while(
    $row mysql_fetch_assoc($pplresult)){ 
        
    $body .= "<tr>
            <td>" 
    $row['Sname'] ."</td>
            <td>" 
    $row['Pname'] ."</td>
            <td>" 
    $row['Psize'] ."</td>
            <td>" 
    $row['Pcolour'] ."</td>
            <td>" 
    $row['Pquantity'] ."</td>
            <td>" 
    $row['Weblink'] ."</td>
            <td>" 
    $row['comment'] ."</td>
            <td>" 
    $row['Price'] ."</td>
            <td>" 
    $row['Tprice'] ."</td>
            </tr>"
    ;
             
    $totalPrices += $row['Tprice'];
    }
      if(
    0.1*$totalPrices <= 50 )
        {
        
    $totalprice = (0.1*$totalPrices +  $totalPrices);
        }
        else
       {
        
    $totalprice 50 $totalPrices;
            }
    $body .= "<tr>
                <td colspan=8>Total :</td>      
                <td>" 
    $totalprice ."</td>
            </tr>"
    ;
    $body .="</table></body></html>";

       
    //Send email
       
    $emails ="los@yahoo.ca";
    $to $emails
       
    $subject "YOUR ORDER LIST($orderno) FROM REACHEASY"
     
    $headers "From: donotreply@easy.co.uk\r\n"
                
    'MIME-Version: 1.0' "\r\n"
                
    'Content-type: text/html; charset=iso-8859-1' "\r\n"
                
    'Bcc:notification@easy.co.uk' "\r\n";

    mail($to,$subject,$body,$headers); 

  2. #2
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You reset $totalPrice but not $totalPrices;

  3. #3
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tom8 View Post
    You reset $totalPrice but not $totalPrices;
    You know you're a C family programmer when you end a sentence with a semicolon instead of a period

    Good catch btw =P

  4. #4
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    292
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    thanks for helping spot that

  5. #5
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I have made enough of those types of errors so it was easy for me to spot.

    Quote Originally Posted by wonshikee View Post
    You know you're a C family programmer when you end a sentence with a semicolon instead of a period

    Good catch btw =P
    Learn C back in the late 70s. This is the book I learned it from:

    c.jpg


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
  •