[英]Catch dynamic page without use database ID
This is my content.php
.这是我的
content.php
。 I want to show sectors/sector_id=1.php
if some one click one my side bar sectors/sector_id=1.php
then sector pass an ID 1 then it shows some content then another menu then it goes to another page, but it shows only one page sector_id=0.php
and when ID is 1 or 2 it shows sector_id=0.php
this page:我想显示
sectors/sector_id=1.php
如果有人点击我的侧边栏sectors/sector_id=1.php
然后sector 传递一个ID 1 然后它显示一些内容然后另一个菜单然后它转到另一个页面,但它显示只有一页sector_id=0.php
,当ID为1或2时,它显示sector_id=0.php
这个页面:
<?php
if($id==1) include('sectors/sector_id=1.php');
if($id==2) include('sectors/sector_id=0.php');
?>
This is my side bar这是我的侧边栏
<ul id="sector-nav" class="nav">
<li >
<!--<a href="&Itemid=§or_id=1">Fibre</a>-->
<a href="sectors.php?<?php echo $id=1; ;?>">Fibre</a>
</li>
<li >
<!--<a href="&Itemid=§or_id=2">Hand Protection</a>-->
<a href="sectors.php?<?php echo $id=2; ?>">Hand Protection</a>
</li>
<li >
<!--<a href="&Itemid=§or_id=3">Purification Products</a>-->
<a href="sector_id=3.html">Purification Products</a>
</li>
<!-- others <li>'s -->
</ul>
The problem here is how you're trying to pass the variables.这里的问题是您如何尝试传递变量。 If you're Link is:
如果你是链接是:
<a href="sectors.php?1">Fibre</a>
This will not get through to your PHP the way you want.这不会以您想要的方式进入您的 PHP。 I would advise creating the link like so:
我建议像这样创建链接:
<a href="sectors.php?id=1">Fibre</a>
When this link is followed, sectors.php will be able to get that value from $_GET['id']
variable.遵循此链接后,sectors.php 将能够从
$_GET['id']
变量中获取该值。 You can then do:然后你可以这样做:
<?php
if(isset($_GET['id'])){
include('sectors/sector_id=' . $_GET['id'] . '.php');
}
?>
Now, if you do something like:现在,如果您执行以下操作:
<a href="sectors.php?1">Fibre</a>
This can be used too, but will generate a NULL value at the index called 1, $_GET['1']
.这也可以使用,但会在名为 1,
$_GET['1']
的索引处生成一个 NULL 值。 So you could grab the Key versus the value if you wanted.因此,您可以根据需要获取密钥与值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.