无法使用 PHP 递归函数显示面包屑导航
如果有人可以帮助我在 PHP 中使用递归函数方法显示面包屑。
我得到了这个代码:
function getCategoryTreeIDs($qs_type_id) {
$crumbsql = "SELECT parent_id FROM lists WHERE id=$qs_type_id";
$crumbresult = tep_db_query($crumbsql);
$crumbrow = tep_db_fetch_array($crumbresult);
$path = array();
if (!$crumbrow['parent_id'] == '') {
$path[] = $crumbrow['parent_id'];
$path = array_merge($this->getCategoryTreeIDs($crumbrow['parent_id']), $path);
}
return $path;
}
function showCatBreadCrumb($qs_type_id) {
$array = $this->getCategoryTreeIDs($qs_type_id);
$numItems = count($array);
for ($i = 0; $i<=$numItems-1; $i++) {
echo $this->getNameLink($array[$i]) . ' » ';
}
}
但是,当我单击任何链接(类别)时,面包屑没有显示。 显示面包屑代码是否有错误?
任何帮助将不胜感激。过去几个月我一直在寻找线索。
非常感谢!
编辑: 不使用“for”命令显示的代码。
function getCategorytTreeIDs($qs_type_id) {
global $lists;
$crumbsql = "SELECT * FROM lists WHERE id=$qs_type_id";
$crumbresult = mysql_query($crumbsql);
$crumbrow = mysql_fetch_array($crumbresult);
if($crumbrow['parent_id'] == 0) {
$crumbprob = $crumbrow['problem'];
return "<a href='index.php'>Home</a> > <a href='index.php?q=id/$qs_type_id'>".$crumbprob."</a> > ";
} else {
$crumbprob = $crumbrow['problem'];
return getCategoryTreeIDs($crumbrow['parent_id']). "<a href='index.php?q=id/$qs_type_id'>".$crumbprob."</a> >";
}
}
要显示面包屑,我必须手动输入函数和 ID 号。像这样:
echo getCategoryTreeIDs(20);
我的问题是,当某些用户单击类别 id 时,如何自动显示面包屑?
谢谢。
If anyone can help me with display breadcrumbs using recursive function method in PHP.
I got this code :
function getCategoryTreeIDs($qs_type_id) {
$crumbsql = "SELECT parent_id FROM lists WHERE id=$qs_type_id";
$crumbresult = tep_db_query($crumbsql);
$crumbrow = tep_db_fetch_array($crumbresult);
$path = array();
if (!$crumbrow['parent_id'] == '') {
$path[] = $crumbrow['parent_id'];
$path = array_merge($this->getCategoryTreeIDs($crumbrow['parent_id']), $path);
}
return $path;
}
function showCatBreadCrumb($qs_type_id) {
$array = $this->getCategoryTreeIDs($qs_type_id);
$numItems = count($array);
for ($i = 0; $i<=$numItems-1; $i++) {
echo $this->getNameLink($array[$i]) . ' » ';
}
}
But, when i click on any links (categories), the breadcrumb didn't show up.
If there any mistake about the show breadcrumb code?
Any help would be appreciate. I already looking for clue for the last couple months.
Many thanks !
EDIT :
Code to display not using the "for" command.
function getCategorytTreeIDs($qs_type_id) {
global $lists;
$crumbsql = "SELECT * FROM lists WHERE id=$qs_type_id";
$crumbresult = mysql_query($crumbsql);
$crumbrow = mysql_fetch_array($crumbresult);
if($crumbrow['parent_id'] == 0) {
$crumbprob = $crumbrow['problem'];
return "<a href='index.php'>Home</a> > <a href='index.php?q=id/$qs_type_id'>".$crumbprob."</a> > ";
} else {
$crumbprob = $crumbrow['problem'];
return getCategoryTreeIDs($crumbrow['parent_id']). "<a href='index.php?q=id/$qs_type_id'>".$crumbprob."</a> >";
}
}
To show the breadcrumb, i must type manually the function and the id number. Like this:
echo getCategoryTreeIDs(20);
My question is, how i can display the breadcrumb automatically when some users click on the categories id?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要动态显示请求页面的面包屑,您需要检查
q
GET 参数。To display breadcrumbs dynamically for requested pages, you will need to examine the
q
GET parameter.