Pages

Saturday, December 18, 2010

MySQL Result As An Array

/**
* @author irfanudin ridho
* @email irfan.ub@gmail.com
* @data december 18, 2010
* @version 1.0
*
* This function will convert mysql resource from 
* mysql_query() to 2D array.
*
* @param $resouce return value from mysql_query();
* @return $arrData 2D array
**/

function toArray($resource){
    $arrData = array();
    $i = 0;
    while($row=mysql_fetch_array($resource)){
        for($j=0;$j<mysql_num_fields($resource);$j++){
            $arrData[$i][$j] = $row[$j];
        }
        $i++;
    }
    return $arrData;
}

No comments:

Post a Comment