aqua peel使用方法:[php+mysql] XX.php?id=X怎么实现??

来源:百度文库 编辑:高考问答 时间:2024/04/27 22:22:56
上网常见的XX.php?id=X是怎么实现的?
假如我有两个php文件:lanmu.php和show.php,lanmu.php已经写完了(echo "<a href=detail.php?id=".$id." >".$name."</a>";),也能显示。
那我的show.php应该怎么编?
数据库kejian,表lanmu(id,name,text)
我希望点击上面的连接后,显示text。

url中问号后边是要传递的变量,比如xx.php?id=x就是告诉xx.php有一个变量id的值是x,在xx.php中要用 $GET['id']来获得这个值
show.php的写法:
//连接数据库
$host='localhost';
$user='root';
$pwd='password';
$db='kejian';
$conn=mysql_connect($host,$user,$pwd) or die("不能连接到服务器");
mysql_select_db($db,$conn);
//获取id的值
$id=$GET['id'];
//查询并显示
$sql="select * from lanmu where id=".$id;
$result=mysql_query($sql,$conn) or die('查询错误');
$row=mysql_fetch_array($result);
$name=$row['name'];
$text=$row['text'];
//处理text中的空格和折行
$text=preg_replace("/ /"," & nbsp;",$text);
$text=preg_replace("/\r\n/","<br>",$text);

echo $name;
echo $text;