Reputation: 227
I try the following code but only one recorde will come
function redeem()
{
$this->db->select('questionEng');
$this->db->from('question');
$query=$this->db->get();
foreach($query->result_array() as $result)
{
print_r($result);die;
}
$this->load->view('admin/redeem');
}
Only one record is coming.please help me
Upvotes: 1
Views: 527
Reputation: 1390
You can do this.
function redeem()
{
$this->db->select('*');
$this->db->from('question');
$query=$this->db->get();
$results = $query->result_array();
echo "<pre>";
print_r($results); // to print results
echo "<pre>";
$this->load->view('admin/redeem',$results); //pass to view
}
Upvotes: 0
Reputation: 7023
remove die;
at all, also why you print result you should pass it to your view then read in view:
function redeem()
{
$this->db->select('questionEng');
$this->db->from('question');
$query=$this->db->get();
$arr_data = $query->result_array() ;
$this->load->view('admin/redeem', $arr_data);
}
Upvotes: 0
Reputation: 107
public function REDEEM()
$this->db->select('questionEng' );
$this->db->from('question');
$this->db->where(select any colum you want);
$query=$this->db->get();
$list=$query->result();
return $list;
Then load the model in controller as $res = $this->your model name->REDEEM(); echo json_encode($res);exit; or load view in place of json
Upvotes: 0
Reputation: 951
In your code you have used die in for loop. So you script will stop working after first looping. So you script printing only one record.
function redeem()
{
$this->db->select('questionEng');
$this->db->from('question');
$query=$this->db->get();
foreach($query->result_array() as $result)
{
print_r($result);
}
die;
$this->load->view('admin/redeem');
}
Upvotes: 0
Reputation: 2408
function redeem()
{
$this->db->select('questionEng');
$this->db->from('question');
$results = $this->db->get()->result_array();
foreach($results as $result)
{
echo "<pre>";
print_r($result);
echo "<pre>";
}
die;
$this->load->view('admin/redeem');
}
Upvotes: 1