SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    eCommerce specialist hotnuts21's Avatar
    Join Date
    Apr 2002
    Location
    Aberystwyth, UK
    Posts
    1,355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Foreach loop and If statements.

    I cant seem to see why this bit of code is not working

    The bit that is the problem is under Check the addresses. Basically there are 3 if statements.
    The first checks to see if $change has a value of 1 or 0. If its 1 then it misses the other if statements out and carries on with the loop.
    The second checks to see if $edited is empty, if it is then it misses the last statement and carries on with the foreach loop.
    The last one compares the 3 addresses for that order gives $addconf a value of 1 or 2.

    Now the script works fine, the first 5 results all have a $change value of 1, so that $addconf doestn have a value (it was never given one). However once the a $change value of 0 is found, that row of data shows the $addconf value, but for some reason all the other rows after that, have a $addconf value too, whether or not they are assigned a 1 or 0 by the $change value.
    For some reason after it encounters a $change value of 0 it runs through the whole if statements for each row, and I dont want it to.

    So where am i going wrong with this?
    PHP Code:
     // Cycle through $orders
         
    foreach ($orders as $key => $output) {
             
    // This outputs all the data
             
    echo $output['orders_id'] . SEP;
             echo 
    $output['orders_stores_id'] . SEP;
             echo 
    $output['date_purchased'] . SEP;
             echo 
    $output['customers_id'] . SEP;
             echo 
    $output['orders_status'] . SEP;
             echo 
    $output['payment_method'] . SEP;
             echo 
    $output['order_taker'] . SEP;
             
    // Foreach can't take $products[$key], so do this
             
    $product $products[$key];
             
    // We can't have a two seperators, can we?
             // If $first is true, no PSEP is outputted
             
    $first true;
             
    // Loop through all the products, and output them
             
    foreach ($product as $poutput) {
                 if(!
    $first) echo PSEP; else $first false;
                 echo 
    $poutput['products_model'] . PSEP;
                 echo 
    $poutput['products_quanity'] . PSEP;
                 echo 
    $poutput['final_price'];
             }
     
             
    //check the addresses per order.
             
    $change=$output['customers_address_changed'];
             
    $edited=$output['order_taker'];
             
    $add1=$output['address'];
             
    $add2=$output['delivery_address'];
             
    $add3=$output['billing_address'];
             echo 
    PSEP $edited .PSEP;
             if (!
    $change == '1') {
             
                if (empty(
    $edited)) {
                 
                   if (
    $add1 == $add2 and $add1 == $add3 ) {
                   
    $addconf '1';
                   } else {
                   
    $addconf '2';
                   }
                }
             }
             
             
    // Output all the final info
             
    echo PEND $addconf PSEP;
             echo 
    $change PSEP;
             echo 
    $output['able_cus_id'] . '<br />';
             echo 
    $output['address'] . '<br />';
             echo 
    $output['delivery_address'] . '<br />';
             echo 
    $output['billing_address'] . '<br />';
             
             
             
         } 
    Search & Rescue Aberystwyth Lifeboat
    CSS Tutorials/Guides

    Sitepoint signatures are not visible to Search Engines More info

  2. #2
    eCommerce specialist hotnuts21's Avatar
    Join Date
    Apr 2002
    Location
    Aberystwyth, UK
    Posts
    1,355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I always sort these things either just after I have posted or or well never actually!

    Anyway found the problem, needed to clear the $addconf variable.
    Search & Rescue Aberystwyth Lifeboat
    CSS Tutorials/Guides

    Sitepoint signatures are not visible to Search Engines More info


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
  •