douyan3478 2013-07-03 13:13
浏览 9

将数据附加到锚标记

i am new to PHP , i want to append data like query string and data i will recieve by $_GET[] or $_POST[], but have facing a problem

i have done something like this <a href="?ref=login_detail?id=<?php echo $car_id; ?>">Hello</a>

this ?ref=login_detail is a function which navigate me to another page. How can I pass $car_id to anchor tag so that is available in another page?

Here is function

public function login_detail(){

    include('display/car_detail.php');

}
  • 写回答

1条回答 默认 最新

  • dongxing2692 2013-07-03 13:18
    关注

    First of all - only first parameter in URL should be prefixed will ?, every other should be prefixed with &.

    So your URL should look like:

    <a href="?ref=login_detail&id=<?php echo $car_id ?>">Hello</a>
    

    Note the & instead of second ?.

    After this, in the target script (which is probably index.php) you can catch your $car_id using:

    var_dump($_GET['id']);
    

    This should print the $car_id you pass to it by clicking the link.


    Going further, depending on your architecture you can change your method to accept some parameters like this:

    class Obj
    {
        public function login_detail($id)
        {
            //do something with passed $id
            echo $id;
        }
    }
    
    (...)
    $obj = new Obj();
    $obj->login_detail($_GET['id']);
    

    or just use it within the method itself:

    class Obj
    {
        public function login_detail($id)
        {
            echo $_GET['id'];
        }
    }
    $obj = new Obj();
    $obj->login_detail();
    
    评论

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算