Here is a method to create array of a table from the database.
Create one file application/libraries/MyDbArray.php
Paste the following content to it.
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class MyDbArray
{
public $CI;
public $db_array=array();
function __construct()
{
$this->CI=& get_instance();
$query=$this->CI->db->get('ci_content');
$this->db_array=$query->result();
}
}
?>
class MyDbArray
{
public $CI;
public $db_array=array();
function __construct()
{
$this->CI=& get_instance();
$query=$this->CI->db->get('ci_content');
$this->db_array=$query->result();
}
}
?>
Controller
<?php
class dbarray extends Controller
{
function __construct()
{
parent::Controller();
$this->load->library('MyDbArray');
}
function index()
{
print_r($this->mydbarray->db_array);
}
}
?>
class dbarray extends Controller
{
function __construct()
{
parent::Controller();
$this->load->library('MyDbArray');
}
function index()
{
print_r($this->mydbarray->db_array);
}
}
?>
No comments:
Post a Comment