[英]how to get all the records from mysql table in codeigniter
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 只有一条记录来了。请帮助我
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');
}
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');
}
remove die;
清除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);
}
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(); 然后将模型加载到控制器中,如下所示:$ res = $ this->您的模型名称-> REDEEM(); echo json_encode($res);exit; echo json_encode($ res);退出; or load view in place of json 或加载视图代替json
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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.