新的 php 动态页面
所以我有一个包含许多“文章标题”和“文章正文”的 mysql 表,
我的主页是 php,它只检索所有文章标题并显示它。
我希望这些标题具有超链接,当您单击它时,它会转到一个显示标题和文章正文的新页面。
不使用 fcreate 或 fwrite,因为这会生成永久的新页面。
如何动态创建一个新的 php 页面?
谢谢
So I have a mysql table of many 'article title' and 'article body's
My main page is php which retrieves just all the article titles and displays it.
I want these titles hyperlinked, when you click on it it goes to a new page which displays both title and article body.
not using fcreate or fwrite as this makes a permanent new page.
how would one make a new php page on the fly?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不创建一个article.php 文件,向该文件传递一个在数据库中查找相应文章的参数?
您可以放置一个类似
http://www.example.com/article.php?page=1
的链接,其中 1 是表中的某种索引。然后,article.php 包含一些代码,用于获取$_GET['page']
变量并在数据库中查找标题和正文。您必须确保您不会受到 SQL 注入攻击,但这似乎正是您想要做的。
就像评论者提到的那样:如果您确实反对在 url 中包含查询,您可以使用 mod_rewrite (或 Web 服务器中的等效项)将 URL 重写为等效的 PHP 页面。
Why don't you just create an article.php file, which is passed an argument that looks up in your database for the corresponding article?
You would put a link like
http://www.example.com/article.php?page=1
, where 1 is some sort of index in the table. Then article.php contains some code to take the$_GET['page']
variable and look up the title and body in the database.You'll have to make sure you aren't vulnerable to SQL Injection attacks, but this seems to be what you're looking to do.
Like the commenter mentioned: if you are really against having the query in the url, you could use mod_rewrite (or the equivalent in your web server) to rewrite a URL to an equivalent PHP page.