dpyic24480 2012-07-13 17:03
浏览 16
已采纳

如何将递归的php面包屑更改为链接?

I'm working an a shopping cart with a page called display.php. This page is called repeatedly as you go through the navigation, always calling itself but querying for new, more specific things. I am trying to make breadcrumbs that will provide links to previous pages, but it's proving to be tricky.

This part of display.php retrieves "id", which the query uses to find things, and breadcrumbs, which is the previous breadcrumbs string. "id" is always added to the breadcrumbs string.

$id = $_GET['id'];
$breadcrumbs=$_GET['breadcrumbs'];
$breadcrumbs = $breadcrumbs." > ".$id;
echo $breadcrumbs

As the id variable is used to query for things, links are generated to go to display.php all over again but to query for something new and take the breadcrumbs string with it. <a href="http://www.myurl.com/display.php?id='.$name.'&depth='.$sub_level.'&breadcrumbs='.$breadcrumbs.'"><img src="imagen/logo1.jpg" alt="" width="100" height="100" /><br>'. $name . '</a>

Each time I go to a new page, the breadcrumbs display visibly, but how can I safely change these string statements into links? an can't carry another string inside it safely. I think it's possible if I explode the breadcrumb string with the > character as the delimiter. How can I fix this up so it will display nice links in the breadcrumb string?

    $breadlist = explode(" > ", $breadcrumbs);

    $linkarray = array();
    foreach $breadlist as $breadlink
    {
        $linkarray($j) = "<a href=display.php?id=".$breadlink($j)."?breadcrumbs=".$breadcrumbs.">".$breadlist($j)."";
    };
  • 写回答

1条回答 默认 最新

  • doudinghan8319 2012-07-13 17:09
    关注

    Two apparent problems (among some other small fixes):

    1. You need to urlencode() your URLs.
    2. You need to access arrays with [], not ().

    Here is an example to get you started:

    $breadlist = explode(" > ", $breadcrumbs);
    
    $linkarray = array();
    foreach( $breadlist as $breadlink)
    {
        $url = 'display.php?id=' . $breadlink . '&breadcrumbs='.$breadcrumbs;
        $linkarray[] = '<a href="' . urlencode( $url) . '">' . $breadlink . '</a>';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测