简体   繁体   中英

Include file.php + id. Is this possible with php?

I've built my site with php include and the index is as follows:

Menu.php (menu system)
main.php (Index site)
footer.php (footer obv.)

Anyway, when main.php (index) opens, I've added a news script that uses $_GET to fetch the news-data from our mysql database. This generates an ID for each news, and it shows only a few characters of the full news.

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 )?

It gives me syntax error when I'm trying to use <?php include in the link since it's already using <?=$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. Is there something I can do more simple than changing the menu to 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. 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.

leave your link as is, it's fine.
do not include main into news.

include only menu and footer into news.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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