简体   繁体   English

包括file.php + id。 这可能与php吗?

[英]Include file.php + id. Is this possible with php?

I've built my site with php include and the index is as follows: 我已经用php include构建了我的网站,索引如下:

Menu.php (menu system) Menu.php (菜单系统)
main.php (Index site) main.php (索引站点)
footer.php (footer obv.) footer.php (页脚观测)

Anyway, when main.php (index) opens, I've added a news script that uses $_GET to fetch the news-data from our mysql database. 无论如何,当main.php (索引)打开时,我添加了一个新闻脚本,该脚本使用$_GET从我们的mysql数据库中获取新闻数据。 This generates an ID for each news, and it shows only a few characters of the full news. 这将为每个新闻生成一个ID,并且仅显示完整新闻的几个字符。

So, I've added a link in each news that says "Read more" to expand the news, it looks like this: 因此,我在每个新闻中都添加了一个链接,上面写着“阅读更多”以扩展新闻,它看起来像这样:

<a href="news.php?id=<?=$row['id']?>">Read More</a></p>

So, is there a way for me to include this site (replace news.php?id=x with main.php )? 因此,有没有办法让我包括此站点(用main.php替换news.php?id=x )?

It gives me syntax error when I'm trying to use <?php include in the link since it's already using <?=$row['id']?> . 当我尝试在链接中使用<?php include时,它给了我语法错误,因为它已经在使用<?=$row['id']?>

The only help I got so far are people telling me to change the menu system to Javascript (Ajax, Jquery) but I'm not too familiar with this. 到目前为止,我得到的唯一帮助是有人告诉我将菜单系统更改为Javascript(Ajax,Jquery),但是我对此不太熟悉。 Is there something I can do more simple than changing the menu to javascript? 除了将菜单更改为javascript之外,我还能做些更简单的事情吗?

Thanks for your help and understanding, 感谢您的帮助和理解,

Have a great day! 祝你有美好的一天!

将其更改为main.php ,得到的id值main.php ,它传递给你的新闻功能。

Yeah, include basically adds the code of another file to the execution of the code you are using. 是的,include基本上会将另一个文件的代码添加到您正在使用的代码的执行中。 So if you already have the variable in you index file can just use it in your menu file. 因此,如果索引文件中已有变量,则可以在菜单文件中使用它。

If the menu file has to be loaded on it own sometimes you can do a conditional for the existence of the GET, then the existence of the variable in your index file, and finally if none of them exit, set a default value. 如果菜单文件必须自己加载,那么有时您可以为GET的存在做一个条件,然后在索引文件中存在该变量,最后如果它们都不存在,请设置默认值。

leave your link as is, it's fine. 保持链接不变,就可以了。
do not include main into news. 不要将main纳入新闻中。

include only menu and footer into news. 在新闻中仅包含菜单和页脚。

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

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