dongyong3590 2016-02-25 20:32
浏览 76
已采纳

如何在PHP中的链接中“添加”两个GET

There are two menus and both were made in order to filter the main content of my website. The Menu one will filter the category and the Menu two will filter the brand.

When clicking in a menu 01 option, it will output: mywebsite.com/?cat=accessories

When clicking in a menu 02 option, it will output: mywebsite.com/?brand=medicate

My main question is how can I get both together when one of them is already set, something like: mywebsite.com/?category=accessories&brand=medicate

Here is my basic code:

<h1>Menu One</h1>
<ul>
  <li><a href="?category=accessories">Option 01</a></li>
  <li><a href="?category=bolts">Option 01</a></li>
  <li><a href="?category=tools">Option 01</a></li>
</ul>

<h1>Menu Two</h1>
<ul>
  <li><a href="&brand=medicate">Brand 01</a></li>
  <li><a href="&brand=diasyst">Brand 02</a></li>
  <li><a href="&brand=clement">Brand 03</a></li>
</ul>
  • 写回答

4条回答 默认 最新

  • douhaodang0403 2016-02-25 20:45
    关注

    When you're displaying the menus, if one of the other filters is already set, you can add that to the URL in the other menu.

    $cat = isset($_GET['category']) ? '&category=' . $_GET['category'] : '';
    $brand = isset($_GET['brand']) ? '&brand=' . $_GET['brand'] : '';
    ?>
    
    <h1>Menu One</h1>
    <ul>
      <li><a href="?category=accessories<?php echo $brand ?>">Option 01</a></li>
      <li><a href="?category=bolts<?php echo $brand ?>">Option 01</a></li>
      <li><a href="?category=tools<?php echo $brand ?>">Option 01</a></li>
    </ul>
    
    <h1>Menu Two</h1>
    <ul>
      <li><a href="?brand=medicate<?php echo $cat ?>">Brand 01</a></li>
      <li><a href="?brand=diasyst<?php echo $cat ?>">Brand 02</a></li>
      <li><a href="?brand=clement<?php echo $cat ?>">Brand 03</a></li>
    </ul>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

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