Triple Nested Loops

This is an archive of the phpBB 2.0.x support forum. Support for phpBB2 has now ended.
Forum rules
Following phpBB2's EoL, this forum is now archived for reference purposes only.
Please see the following announcement for more information: viewtopic.php?f=14&t=1385785

Triple Nested Loops

Postby adaml » Mon Nov 28, 2005 4:17 pm

Wow! Iv got a problem, im making a store system for phpbb and im having trouble displaying the extras which need to be configured per each product.

There are multiple products, multiple extras for each product, and multiple options for each extra!

Which all makes for a messy html file, anyway iv completely lost myself in all the code. And now triple nested loops arent working!

First i have a switch - to show which step is in use, then a loop on the products, then a loop on the extras.

My HTML:
Code: Select all
         <!-- BEGIN product_extras -->
         <form action="breeder.php?mode=order&basket=view" method="post" enctype="multipart/form-data">
         <!-- BEGIN product_loop -->
         <table width="90%" border="0" align="center" cellpadding="2" cellspacing="2">
             <tr>
             <td>{product_extras.product_loop.PRODUCT_NAME}</td>
          </tr>
           <!-- BEGIN loop_extras -->
              <tr>
             <td><div class="gensmall">{product_extras.loop_extras.NAME}</div></td>
                <td><div class="gensmall">{product_extras.loop_extras.FIELD}</div></td>
              </tr>
              <!-- END loop_extras -->
              <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td><a href="breeder.php?mode=order&checkout=1&step=verify" class="gensmall">Continue</a></td>
              </tr>
            </table>
         <!-- END product_loop -->
         </form>
         <!-- END product_extras -->


Now, my php:

Code: Select all
            $template->assign_block_vars("product_extras", array());

            //* Grab Products + Check for Extras.
            $sql = "SELECT * FROM breeder_baskets INNER JOIN breeder_products ON breeder_baskets.product_id = breeder_products.product_id WHERE user_id = '$userdata[user_id]'";
            if(!$result = $db->sql_query($sql)){ message_die(GENERAL_ERROR, "Couldnt Find Your Basket.", '', __LINE__, __FILE__, $sql); }
            $extra = 0;
            while($rows = $db->sql_fetchrow($result)){
               if($rows[product_extras] == 1){
                  $template->assign_block_vars("product_loop", array("PRODUCT_NAME" => $rows[product_name]));
                  $product_sql = "SELECT * FROM breeder_product_extras WHERE product_id = '$rows[product_id]'";
                  if(!$product_result = $db->sql_query($product_sql)){ message_die(GENERAL_ERROR, "Couldnt Find Your Basket.", '', __LINE__, __FILE__, $sql); }
                  while($product_extras = $db->sql_fetchrow($product_result)){
                     $select = "<select name=". $product_extras[extra_name] . ">";
                     $extra_sql = "SELECT * FROM breeder_extra_options WHERE extra_id = '$product_extras[extra_id]'";
                     if(!$extra_result = $db->sql_query($extra_sql)){ message_die(GENERAL_ERROR, "Couldnt Find Your Basket.", '', __LINE__, __FILE__, $sql); }
                     while($extras = $db->sql_fetchrow($extra_result)){
                        $select .= "<option value='" . $extras[extra_value] . "'>" . $extras[extra_name] . "</option>";
                     }
                     $select .= "</select>";
                     $template->assign_block_vars("product_extras.product_loop.loop_extras", array("NAME" => $product_extras[extra_name], "FIELD" => $select));
                     
                  }
                  //* Show All the Extra Stuff that Needs to be Completed.
                  $extra = 1;
               }
            }



Can anyone help me and spot where i have gone wrong?


Thank you in advance for all the help! Keep up the good work guys!
adaml
Registered User
 
Posts: 29
Joined: Wed Oct 19, 2005 8:05 am
Location: UK

Return to 2.0.x Support Forum

Who is online

Users browsing this forum: No registered users and 6 guests