PHP開發中 mysql_query()查詢出結果集轉數組的方法

<?php

$query="select * from table_xyz";

$result = mysql_query($query) or die(mysql_error());

$arr_table_result=mysql_fetch_full_result_array($result);

function mysql_fetch_full_result_array($result)

{

   $table_result=array();

   $r=0;

   while($row = mysql_fetch_assoc($result)){

       $arr_row=array();

       $c=0;

       while ($c < mysql_num_fields($result)) {        

           $col = mysql_fetch_field($result, $c);    

           $arr_row[$col -> name] = $row[$col -> name];            

           $c++;

       }    

       $table_result[$r] = $arr_row;

       $r++;

   }    

   return $table_result;

}

echo $arr_table_result[2]['id'];

?>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章