作者s792935 (阿葆)
看板PHP
标题[请益] 读取资料库内资料表的内容存进html的table里
时间Tue Mar 22 13:13:25 2011
我想要从"test"资料库中的"road"资料表中取出5个栏位的资料存进自己所画的table里
5个栏位分别是"category","location","description","date","time"
因为资料表内的资料笔数不固定(因为资料库更新後读取进来的资料笔数会被影响到)
如何写出从资料库内读取五个栏位分别进入所画的table里的五个栏位呢?
以下是我用DW写的php程式,现在只能显示出第一笔资料在table里
想请问各位是否在哪边需再加上判断式(while回圈)?
谢谢各位的解答~
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<?php
mysql_pconnect("localhost","帐号","密码"); //连结资料库
mysql_select_db("test");//选择资料库
$result = mysql_query("SELECT * FROM road"); //取得资料表
$row_result = mysql_fetch_assoc($result); //取得资料表内的资料
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>国道甜心</title>
</head>
<body>
<table width="1040" height="55" border="1" align="center" cellpadding="0"
cellspacing="0">
<tr bgcolor="#0099FF">
<td width="111" bgcolor="#0099FF"><div align="center">类别</div></td>
<td width="161"><div align="center">地点</div></td>
<td width="546" bgcolor="#0099FF"><div align="center">路况说明</div></td>
<td width="105" bgcolor="#0099FF"><div align="center">日期</div></td>
<td width="105" bgcolor="#0099FF"><div align="center">时间</div></td>
</tr>
<tr>
<td><div align="center">
<?php $category="category"; echo $row_result[$category]; ?>
</div></td>
<td><div align="center">
<?php $location="location"; echo $row_result[$location]; ?>
</div></td>
<td><?php $description="description"; echo $row_result[$description];
?></td>
<td><div align="center">
<?php $date="date"; echo $row_result[$date]; ?>
</div></td>
<td><div align="center">
<?php $time="time"; echo $row_result[$time]; ?>
</div></td>
</tr>
</table>
</body>
</html>
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 123.205.55.27
※ 编辑: s792935 来自: 123.205.55.27 (03/22 13:15)
※ 编辑: s792935 来自: 123.205.55.27 (03/22 13:19)
1F:→ lazyhome:第二个<tr> 前面加while噜,书上的教学或范例多看熟一点啦 03/22 13:30