[請益] 讀取資料庫內資料表的內容存進html的ta …

看板PHP作者 (阿葆)時間14年前 (2011/03/22 13:13), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/2 (看更多)
我想要從"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" "" rel="nofollow">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="" rel="nofollow">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)

03/22 13:30, , 1F
第二個<tr> 前面加while嚕,書上的教學或範例多看熟一點啦
03/22 13:30, 1F
文章代碼(AID): #1DY2_t6Z (PHP)
文章代碼(AID): #1DY2_t6Z (PHP)