简体   繁体   English

如何在href中的PHP Passing ID中插入变量

[英]How to insert variable in PHP Passing ID in href

i have code to passing ID in href in the below : 我在下面的href中有传递代码的代码:

<a href="<?php echo base_url(); ?>app_summary/hoplist/<?php echo $row['id']; ?>" class="large-box">

with my link href code in above, i want to insert these variable : 与上面的链接href代码一起,我想插入以下变量:

$first = '2018/01/20';
$end = '2018/01/25';

how to insert varibles above into my PHP passing ID in href? 如何将上面的变量插入到href中我的PHP传递ID中?

thanks for advice... 谢谢你的建议...

$first = '2018/01/20';

$end = '2018/01/25';

$first = date("Y-m-d",strtotime($first));

$end = date("Y-m-d",strtotime($end));

<a href="<?php echo base_url('app_summary/hoplist/'.$row['id'].'/'.$first.'/'.$end);?>" class="large-box">

you can Try like this ... 你可以这样尝试...

I'm not sure exactly where you intend to include those variables, but this is how I would do it, of course adjusting for your situation. 我不确定您打算在何处包括这些变量,但这是我的方式,当然可以根据您的情况进行调整。

<?php echo '<a href="' . base_url() . 'app_summary/hoplist/' . $row['id'] . $code . $matrix . date("m/d/Y") . 'class="large-box">'; ?>

edit to show date in example. 编辑以显示示例中的日期。

try this 尝试这个

<a href="<?=base_url('app_summary/hoplist/'.$row['id'] .'/code='. urlencode($code). '/matrix='.urlencode($matrix));?>" class="large-box">

or using http_build_query 或使用http_build_query

<?php
$data = array(
    'code' => '2018/01/20',
    'matrix' => $matrix,
    'other' => 'some text with space'
);

?>

<a href="<?=base_url('app_summary/hoplist/'.$row['id'] .'/'. http_build_query($data));?>" class="large-box">

maybe you can try this : 也许你可以试试这个:

<a href="<?php echo base_url('app_summary/hoplist/'.$row['id'].'/'.$first.'/'.$end);?>" class="large-box">

then in your controller (to show detail) you can separate $first and $end with $this->uri->segment() like this : 然后在您的控制器中(以显示详细信息),您可以使用$this->uri->segment()$first$end分开,如下所示:

  $id = $this->uri->segment(3);
  $frsdate = $this->uri->segment(4);
  $enddate = $this->uri->segment(5);

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

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