2006-03-22 11:50:59小友
php教學3-查詢資料庫
查詢資料庫
語法:mysql_fetch_row(結果變數)
例如:mysql_connect("localhost","root","123456");
$db = mysql_select_db("mysql");
$query="select * from mysql order by number desc";
$rows = mysql_query($query);
$row = mysql_ferch_row($rows);
範例:
<?php
mysql_connect("localhost","root","123456") or
die("could not connect");
mysql_select_db("mysql");
$result = mysql_query("select id, name from mytable");
while($row = mysql_fetch_array($result, mysql_num)){
printf("id:%s name: %s,$row[0],$row[1]);
}
mysql_free_result($result);
?>
語法:mysql_fetch_row(結果變數)
例如:mysql_connect("localhost","root","123456");
$db = mysql_select_db("mysql");
$query="select * from mysql order by number desc";
$rows = mysql_query($query);
$row = mysql_ferch_row($rows);
範例:
<?php
mysql_connect("localhost","root","123456") or
die("could not connect");
mysql_select_db("mysql");
$result = mysql_query("select id, name from mytable");
while($row = mysql_fetch_array($result, mysql_num)){
printf("id:%s name: %s,$row[0],$row[1]);
}
mysql_free_result($result);
?>