CI_DB_result::result_array PHP Method

result_array() public method

Query result. "array" version.
public result_array ( ) : array
return array
    public function result_array()
    {
        if (count($this->result_array) > 0) {
            return $this->result_array;
        }
        // In the event that query caching is on, the result_id variable
        // will not be a valid resource so we'll simply return an empty
        // array.
        if (!$this->result_id or $this->num_rows === 0) {
            return array();
        }
        if (($c = count($this->result_object)) > 0) {
            for ($i = 0; $i < $c; $i++) {
                $this->result_array[$i] = (array) $this->result_object[$i];
            }
            return $this->result_array;
        }
        is_null($this->row_data) or $this->data_seek(0);
        while ($row = $this->_fetch_assoc()) {
            $this->result_array[] = $row;
        }
        return $this->result_array;
    }

Usage Example

Example #1
0
 /**
  * Untuk menghasilkan data excel
  * 
  * @access public
  * @return Excel_generator
  */
 public function generate()
 {
     $start = $this->start;
     if (count($this->header) > 0) {
         $abj = 1;
         foreach ($this->header as $row) {
             $this->getActiveSheet()->setCellValue($this->columnName($abj) . $this->start, $row);
             if ($this->header_bold) {
                 $this->getActiveSheet()->getStyle($this->columnName($abj) . $this->start)->getFont()->setBold(TRUE);
             }
             $abj++;
         }
         $start = $this->start + 1;
     }
     foreach ($this->query->result_array() as $result_db) {
         $index = 1;
         foreach ($this->column as $row) {
             if (count($this->width) > 0) {
                 $this->getActiveSheet()->getColumnDimension($this->columnName($index))->setWidth($this->width[$index - 1]);
             }
             $this->getActiveSheet()->setCellValue($this->columnName($index) . $start, $result_db[$row]);
             $index++;
         }
         $start++;
     }
     return $this;
 }