我在PHP中有一个问题。
我有一个网站,它从mysql中保存新闻(标题,日期,作者,描述)一切正常,我有一个页面,当用户点击标题时他去了readmore.php?id = 10(例如)
现在我的问题是如何在一个页面中阅读完整的故事
例如index.php?id = 10,我不想发送readmore.php页面,我想在一个页面中,我该怎么做?
答案 0 :(得分:2)
check there is **id** querystring .
if(isset($_GET["id"]))
{
// show news which belongs to **id**
}
else
{
// list all news
}
但是不要忘记验证$ _GET [“id”]变量。例如,如果 ids 仅为数字,则可以选中使用* is_numeric(); *等。
答案 1 :(得分:1)
这实际上取决于你当前的脚本,但也许你可以修改readmore.php页面只发送页面正文,然后在你需要完整故事的index.php中发送require ("readmore.php");
,如果参数(id)是一样的。然后,您可以使用某些东西来显示/隐藏div中的全部新闻。例如。
答案 2 :(得分:0)
您可以使用jquery插件,例如jQuery Expander Plugin
答案 3 :(得分:0)
也许你可以发送一个get变量,如:index.php?id = 10& full = 1。所以,如果index.php中的满== 1,则可以显示所有新闻,否则使用substr()
切换新闻答案 4 :(得分:0)
index.php <- normal news page
index.php?readstory=10 <- will display story with id 10
index.php中的
if(isset($_GET['readstory'])) {
$story_id = $_GET['readstory'];
display_story($story_id);
}
else {
display_news();
}