困惑使Sitemap使用PHP编码 [英] confused to make sitemap using php coding

查看:94
本文介绍了困惑使Sitemap使用PHP编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个CMS网站,现在我试图使php编码的网站地图,但我所做的代码是不完整的。即它不显示所有的子菜单数据。



请观看此图片。根据这个图像,我有很多其他子菜单下重量训练(子菜单的健身运动),但他们是不可见的。



请指导/帮助我解决此问题



我的php代码

p>

  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); // ie select * from menu where parent_id = $ mid
if(empty($ submenucon)){?>
---
<?php
} else {
foreach($ submenucon as $ subtrow){

<?php echo'< li style =color:grey; margin:>'。$ subtrow-> menu_name。< / li>< br / >
<?php
}
}
?>
< / ul>
< / p>
<?php
$ i ++;
}
}?>


解决方案

在最普通/朴素的方式)在数据库。因此,你应该做的第一件事是建立一个基于返回的行的树状结构,然后再遍历它为了显示。



你可以阅读更多在这里解析树状表格:



p>

实施分层数据库中的数据结构



将平面表解析成树的最有效/优雅的方法是什么?


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++;
                    }
                }    ?> 

解决方案

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?

这篇关于困惑使Sitemap使用PHP编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆