7 Replies Latest reply on Apr 8, 2009 10:36 PM by Albert S.

    dynamic nav with categories and subcategories

    beatzMalone Level 1

      Hey guys im in the middle of customizing a php cms app to fit my site...im basically reusing some of its code.
      im currently working on the nav which is an accordion spry i will be using php to get categories and subcategories and echoing them so as to create the accordion.

       


      the subcategories should appear under its category. In the database there are one category for many subcats and one subcat for mutiple products...so tbl_subcat has its own id plus the cat_id as the foreign key.
      the origianl nav script echoed <li></li> for only categories..i adopted it for divs
      here is the page http://vaughntucker.com/exflowers/about.php?

       


      The problem im having is loading all the subcats under each category it only does one row and it repeats the same subcat for the rest of the categories so i know my php
      logic is off but im stumped...

       

      here is the entire code http://vaughntucker.com/exflowers/about.txt

       

      Thanks

        • 1. Re: dynamic nav with categories and subcategories
          Dan.Smith Level 2

          At what line does it select the subcategories in your code?

          • 2. Re: dynamic nav with categories and subcategories
            beatzMalone Level 1

            The line where it says

            //get all subcats for side nav//
            at the begining of the code...
            • 3. Re: dynamic nav with categories and subcategories
              Albert S. Level 3

              Hi Malone,

               

              I took a quick look at your code and only saw one do while statement for the main categories. I didnt see one for the sub categories.

              You have one table that is categories and one table with sub categories witha  foriegn key. I think you will have success using a "nested repeat region" so it loops thru the sub categories.

              • 4. Re: dynamic nav with categories and subcategories
                beatzMalone Level 1

                Ok ill research the nested repeat region im not too familair

                 

                i tried the double do while statement and ran into problems...i think i have the logic confused..

                i  just need to wrap my mind around the logic i could take it from there..

                 

                how would i implement that second dowhile ..and get each subcat echoed under its parent

                only those that are related to the category.... just the logic of it would do.

                • 5. Re: dynamic nav with categories and subcategories
                  Albert S. Level 3

                  Hi Malone,

                   

                  Try this:

                   

                  Create blank page.

                   

                  Go to Developer Tools Tab:

                       Click on "Nested Repeat Region" // 3rd icon from right

                            Enter information for Master table // Main category

                                 Then Detail table // Sub category

                  Click Next

                            Select List so it doesnt add table information to the page.

                  Click Finish

                       You now have your repeat region.

                   

                  Test on your server.

                   

                  That will give you working logic that you can copy/paste to your actual page. You will just need to weave it into the Accordian Panel. (Not hard to do)

                   

                  I would post a working example for you but I have to take care of some stuff while I still have daylight left.

                  • 6. Re: dynamic nav with categories and subcategories
                    beatzMalone Level 1

                    well first let me say im using dm cs4

                     

                    there is no developer tab however on the spry tab there is a spry repeat region third icon from right

                     

                    i clicked but it asked for a spry data set which turns out can only be xml or html and im using php and mysql remember.

                     

                    i created recordset with dreamweaver and tried using the repeat region server behavior. and again it woks for category but says unable to do nested region on the same contaniner so im back at square 1..so that doesnt work

                     

                     

                    but if you could just explain that do while thing i think i'd get it.

                    • 7. Re: dynamic nav with categories and subcategories
                      Albert S. Level 3

                      Hi Malone,

                       

                      I thought since you were posting in the ADDT (Adobe Developer Tools) forum that you had it.

                      Thats fine here is a nested repeat region from DW.

                       

                      <?php

                      //Main Query

                      mysql_select_db($database_db, $db);
                      $query_master1tbl_cat = "SELECT * FROM tbl_cat ORDER BY cat_name";
                      $master1tbl_cat = mysql_query($query_master1tbl_cat, $db) or die(mysql_error());
                      $row_master1tbl_cat = mysql_fetch_assoc($master1tbl_cat);
                      $totalRows_master1tbl_cat = mysql_num_rows($master1tbl_cat);

                       

                      // Sub Query //Take notice of the 123456789 that will be replaced as it loops thru the query

                      mysql_select_db($database_db, $db);
                      $query_detail2tbl_subcat = "SELECT * FROM tbl_subcat WHERE cat_id='123456789' ORDER BY subcat_name";
                      $detail2tbl_subcat = mysql_query($query_detail2tbl_subcat, $db) or die(mysql_error());
                      $row_detail2tbl_subcat = mysql_fetch_assoc($detail2tbl_subcat);
                      $totalRows_detail2tbl_subcat = mysql_num_rows($detail2tbl_subcat);
                      ?>

                       

                      <table border="1">
                        <?php

                      // Start of the first do while statement for the main category

                      do { ?>
                          <tr>
                            <td><?php echo $row_master1tbl_cat['cat_name']; // Main Category Name ?></td>
                            <td>

                      <?php

                      // Nested Repeat Region starting code that will take the value (id) from the Main Category table and loop thru the Main Category table
                        if ($totalRows_master1tbl_cat>0) {
                          $nested_query_detail2tbl_subcat = str_replace("123456789", $row_master1tbl_cat['id'], $query_detail2tbl_subcat); // This is where the 123456789 is replaced with the id from the Main Category as it loops
                          mysql_select_db($database_db);
                          $detail2tbl_subcat = mysql_query($nested_query_detail2tbl_subcat, $db) or die(mysql_error());
                          $row_detail2tbl_subcat = mysql_fetch_assoc($detail2tbl_subcat);
                          $totalRows_detail2tbl_subcat = mysql_num_rows($detail2tbl_subcat);
                          $nested_sw = false;
                          if (isset($row_detail2tbl_subcat) && is_array($row_detail2tbl_subcat)) {
                            do { //Nested repeat // Start of 2nd do while statement that loops thru the Sub Categories
                      ?>
                                  <?php
                        //detail2tbl_subcat show if first nested loop version 3
                        if (!isset($nested_sw) || $nested_sw == false) {
                          $nested_sw = true;
                        } else {
                      ?>
                                    ,
                                    <?php
                        } // end show if first nested loop version 3
                      ?>
                                  <?php echo $row_detail2tbl_subcat['subcat_name']; ?>
                                  <?php
                            } while ($row_detail2tbl_subcat = mysql_fetch_assoc($detail2tbl_subcat)); //Nested move next
                          }
                        }
                      ?>
                            </td>
                          </tr>
                          <?php } while ($row_master1tbl_cat = mysql_fetch_assoc($master1tbl_cat)); ?>
                      </table>

                       

                      <?php
                      mysql_free_result($master1tbl_cat);

                      mysql_free_result($detail2tbl_subcat);
                      ?>