PHP URL Problem
I have a question in PHP.
I have a website thats hold news from mysql the (title, date, author, description) everything works fine, I have a page when which the user click on the title he go readmore.php?id=10 (for example)
Now my question is how to make to read the full story in one single page
for example index.php?id=10, I don't want to send in the readmore.php page, I want in one single page, h开发者_C百科ow can I make this ?
check there is **id** querystring .
if(isset($_GET["id"]))
{
// show news which belongs to **id**
}
else
{
// list all news
}
But don't forgot validating $_GET["id"] variable. For example, if ids only numeric, you can check use *is_numeric();* etc.
It really depends on your current scripts but maybe you can modify the readmore.php page to only send the body of the page and then require ("readmore.php");
in your index.php where you need the full story, if the parameter (id) is the same. Then you can use something to show/hide the full body of the news in a div, in example.
you can use a jquery plugin for that, for example jQuery Expander Plugin
maybe you could send a get variable like: index.php?id=10&full=1. So, if full == 1 in index.php yo can show all the news, else cut the news with substr()
url like so:
index.php <- normal news page
index.php?readstory=10 <- will display story with id 10
in index.php
if(isset($_GET['readstory'])) {
$story_id = $_GET['readstory'];
display_story($story_id);
}
else {
display_news();
}
精彩评论