1

I have created a CMS website, now I am trying to make site map with php coding, but the code which i have made is not complete. i.e It is not showing all the sub menu data.

Please look at this image . According to this image, I am having many other sub menu under Weight training(sub menu of Fitness Exercises) ,but they are not visible. Why they are not visibile?

Please guide/help me to solve this issue

My php code

   foreach ($query_sitemap as $artrow) {
        $datefromsql = $artrow->created_date;
          $time = strtotime($datefromsql);  ?> 

                <p>    
                        <ul>
                            <?php echo '<b>'.$artrow->menu_name.'</b>'; ?>


                                <?php $submenucon=$this->menumodel->fetch_menu_byPid($artrow->id);//i.e select*from menu where parent_id=$mid
                                 if (empty($submenucon)) { ?>
                                  ---
                                 <?php
                                    } else {
                                         foreach ($submenucon as $subtrow) {
                                             ?>
                                              <?php echo '<li style="color:gray;margin:">'.$subtrow->menu_name.'</li><br/>'; ?>
                                      <?php
                                         }
                                    }
                                 ?>    
                        </ul> 
                        </p> 
                        <?php
                        $i++;
                    }
                }    ?> 
9
  • its very difficult for me. please any one tell me some logic. please Commented Jul 16, 2013 at 10:23
  • Not sure what the problem is, but all you need to do is put one line in the sitemap for each unique page/post, not a line for each menu item unless each item is itself a unique page, The page order in the sitemap is not generally important so you don't have to order it to match your menu. If the logic to get your own site structure is difficult, then perhaps you should consider changing how you structure your database Commented Jul 16, 2013 at 10:26
  • So u have submenus in a submenu ? Then u should use some recursion to fetch all menus Commented Jul 16, 2013 at 10:31
  • @Anigel eg. w3.org/WAI/sitemap.html .what code u think i have to add in my line to make? Commented Jul 16, 2013 at 10:32
  • Just loop through all your pages and add them to the sitemap, categories are not relevant Commented Jul 16, 2013 at 10:33

1 Answer 1

1

You're dealing with a tree structure here represented (in a most siplistic/naive way) in a database. So the first thing you should do is to build a tree-like structure based on returned rows and only then traverse it recrusively in order to display.

You can read more on parsing tree-like tables here:

Is it possible to query a tree structure table in MySQL in a single query, to any depth?

Implementing a hierarchical data structure in a database

What is the most efficient/elegant way to parse a flat table into a tree?

Sign up to request clarification or add additional context in comments.

3 Comments

yeah i saw your example they are similar with my problem. But still i am very confused how to write its code for my above problem. Please modify my question and post answer for it. It will be very useful for me
i found this link paratechnical.blogspot.in/2011/02/… Can u plz write code for my above problem. I am not cable to this type of task but i have to do it, to save my job
Once u got the hang of the nested set approach its realy nice to build dynamic menus

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.