語法:
<?php
mysql_connect("localhost","root","密碼");//與localhost連線、root是帳號、密碼處輸入自己設定的密碼
mysql_select_db("member");//我要從member這個資料庫撈資料
mysql_query("set names utf8");//設定utf8 中文字才不會出現亂碼
$data=mysql_query("select * from member");//從member中選取全部(*)的資料
$rs=mysql_fetch_row($data);//擷取資料的第一行,此句打兩次就會出現第二行,打三次出現第三行...
echo $rs[1]//將 $rs的第一欄顯示在畫面上
?>
<?php echo mysql_num_rows($data)?>//得知資料表中有幾筆資料
- DW中的畫面
- 程式碼:
-
<?php
mysql_connect("localhost","root","密碼");//與localhost連線、root是帳號、密碼處輸入自己設定的密碼
mysql_select_db("member");//我要從member這個資料庫撈資料
mysql_query("set names utf8");//設定utf8 中文字才不會出現亂碼
$data=mysql_query("select * from member");//從member中選取全部(*)的資料?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文件</title>
</head><body>
<table width="546" border="1">
<tr>
<td>編號</td>
<td>姓名</td>
<td>性別</td>
<td>生日</td>
<td>地址</td>
<td>城市</td>
</tr>
<?php
for($i=1;$i<=mysql_num_rows($data);$i++)
{ $rs=mysql_fetch_row($data);
?><tr>
<td><?php echo $rs[0]?></td>
<td><?php echo $rs[1]?></td>
<td><?php echo $rs[2]?></td>
<td><?php echo $rs[3]?></td>
<td><?php echo $rs[4]?></td>
<td><?php echo $rs[5]?></td>
</tr>
<?php }?>
</table>
</body>
</html> - F12預覽畫面
留言列表