我如何为mysql数据库中的每一行创建一个唯一的php页面 [英] how do i create a unique php page for each row in a mysql database

查看:76
本文介绍了我如何为mysql数据库中的每一行创建一个唯一的php页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与php连接的mysql数据库.但是,我希望数据库中的每一行都是唯一的页面.任何人都可以提供有关其工作原理的概述.对于我来说,将数据库的结果显示为完整的表或选定的行很简单,但是我很难从唯一的行创建单个页面.

I have a mysql database connected with php. However, I want each row in the database to be a unique page. Could anyone please provide some sort of overview for how this would work. It is simple for me to display the results of the database as a complete table or selected rows, but I have difficulty in creating individual pages from unique rows.

推荐答案

首先,您不能这样做,否则将很难为表的每一行创建单独的页面.您只需要一页纸就可以完成,并使用$ _GET全局变量来更改您应该查看的站点.

Alright, first off you can't, or it will be difficult to create individual pages for each row of your table. You'll have to do it with one page and take use of the $_GET global to change which site you should view.

例如site.php?id=1

site.php看起来大概像这样

site.php would look something like this roughly

<?php
$connect = mysql_connect('host', 'user', 'pass');
$select_db = mysql_select_db('database_name');

$id = mysql_real_escape_string($_GET['id']);
//Remove LIMIT 1 to show/do this to all results.
$query = 'SELECT `content` FROM `pages` WHERE `id` = '.$id.' LIMIT 1';
$result = mysql_query($query);
$row = mysql_fetch_array($result);

// Echo page content
echo $row['content'];
?>

有了它,您可以请求所需的任何ID并检索该行/页面的内容.

With that you can request any id you want and retrieve the content of that row/page.

这篇关于我如何为mysql数据库中的每一行创建一个唯一的php页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆