简体   繁体   English

使用文件名的PHP crumbtrail

[英]php crumbtrail using file names

Im trying to create a crumb trail for a custom web script that drills down three levels into a link system. 我试图为一个自定义的Web脚本创建一个屑痕迹,该脚本将三个级别的内容向下钻取到链接系统中。 there are not many pages so my idea seem less work than to integrate someone else's script ! 页面不多,所以我的想法似乎比集成别人的脚本要少!

this is how i mark or identify the page in the header of each page 这就是我在每个页面的标题中标记或识别页面的方式

first level page 一级页面

<?php $page = 'index_week'; ?>

second level page 二级页面

<?php $page = 'index_week_list'; ?>

third level page which is also the details page and no deeper levels exist after this 第三级页面,这也是详细信息页面,此后不存在更深层次的信息

<?php $page = 'index_week_ details'; ?>

My questions are... 我的问题是...

1-how do i give each of these a label to that i can show them in the crumb trail and not show ""index_week_ details"" 1-我该如何给这些标签加上标签,以便可以在碎屑痕迹中显示它们,而不显示““ index_week_ details”“

2-how do i link the file name to go back to a previous level with the identifier i used so that it picks up the listing id i used to filter that page's content form the database? 2-如何将文件名与使用的标识符链接回到上一级,以便获取用于过滤数据库页面内容的列表ID?

Below the header are and beginning of each page to see my dilemma ! 页眉下方是每一页的开头,以查看我的困境!

the first lever page 第一个杠杆页面

<?php 
include("inc_login_config.php");
include("inc_gen_constants.php");
include("inc_meta_header.php"); 
require("inc_dbsql.php");
include("inc_link_sql.php");
?>
<?php $page = 'index_week'; ?>
</head>
<body marginwidth="0" marginheight="0">
<!-- End of all general inclusuions -->
<?php
$db = new LinkSQL($dbname); 
$homecataresult = $db->getchildcatalog(0);
$table="linkexcatalog";
mysql_connect           ($dbhost,$dbuser,$dbpassword);
@mysql_select_db        ($dbname);
$result = mysql_query("select catalogid,catalogname,parentid from $table where arentid='0' order by priority asc" );
$num_fields = mysql_num_fields($result);
$num_rows = mysql_num_rows($result);
$row_cnt = 0;
while ($num_rows>$row_cnt)
{
$record = @mysql_fetch_row($result); 
?>
<a href="ba_index_list_lessons.php?id=<?php print "$record[0]"; ?>"><?php print "$record[1]"; ?></A><br>
<?php $row_cnt++;} ?>
<?php mysql_close(); ?>

The other Two PHP files looks much the same except i have different LEVEL page id in them ? 其他两个PHP文件看起来几乎相同,除了我在其中具有不同的LEVEL页面ID? I hope i don't confuse to much ! 我希望我不要混淆太多!

Ta any help appreciated. 任何帮助表示赞赏。

Break up your string (into an array) on _'s, then loop on that array to create the breadcrumbs. 在_上将字符串分解(分成一个数组),然后在该数组上循环以创建面包屑。

Here's a quick example: 这是一个简单的示例:

<?php

$me = 'index_week_details';

//Break into an array
$parts = explode('_', $me);

//Debug
//print_r($parts);

//Create breadcrumbs
$path = '';
foreach($parts as $part) {
  $path .= $part . '_';  

  echo '<a href="' . rtrim($path, '_') . '">' . $part . '</a>' . "\n";
}

You can play with it live here: 您可以在这里现场玩:

http://codepad.org/dFpujKZ8 http://codepad.org/dFpujKZ8

Input: 输入:

index_week_details

Output: 输出:

<a href="index">index</a>
<a href="index_week">week</a>
<a href="index_week_details">details</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM