輸入待尋字串
  <?php
  require("http://php.wilson.gs");  // 回首頁
  echo "http://php.wilson.gs/bible/function.php : 函式:mysql_fetch_array()";


函式:mysql_fetch_array()


mysql_fetch_array

傳回陣列資料。

語法: array mysql_fetch_array(int result, int [result_typ]);

傳回值: 陣列

函式種類: 資料庫功能

內容說明

本函式用來將查詢結果 result 拆到陣列變數中。若 result 沒有資料,則傳回 false 值。而本函式可以說是 mysql_fetch_row() 的加強函式,除可以將傳回列及數字索引放入陣列之外,還可以將文字索引放入陣列中。若是好幾個傳回欄位都是相同的文字名稱,則最後一個置入的欄位有效,解決方法是使用數字索引或者為這些同名的欄位 (column) 取別名 (alias)。值得注意的是使用本函式的處理速度其實不會比 mysql_fetch_row() 函式慢,要用哪個函式還是看使用的需求決定。參數 result_typ 是一個常數值,有以下幾種常數 MYSQL_ASSOC、MYSQL_NUM 與 MYSQL_BOTH。

使用範例

<?php
mysql_connect
($host,$user,$password);
$result mysql_db_query("database","select * from table");
while(
$row mysql_fetch_array($result)) {
  echo 
$row["user_id"];
  echo 
$row["fullname"];
}
mysql_free_result($result);
?>


[ 上一頁 /bible/function.php 下一頁 ]



本站置於 NEC BIGLOBE 地球村網際網路  echo "Copyright © 1999-2001, Wilson Peng";  //隱私權保護政策
  mail("wilson@biglobe.net.tw", "Feedback", $message);
  ?>