I am puzzled because of CodeIgniter's strange behavior. I am fetching some data from Model and returning it to Controller and passing that data from Controller to View.
function index()
{
$data['details'] = $this->Mymodel->Get_Details();
$this->load->view('mypage',$data);
}
public function Get_Details()
{
$query = "
SELECT
*
FROM
tablename
";
$result = $this->db->query($query)->result();
return $result;
}
<?php
print_r($details);
?>
The problem is nothing is displayed in view page. If i give print_r($data);
in Controller
or print_r($result);
in Model
, the result is shown. If in select
, *
is replaced with individual column names then the output is passed from Controller
to View
and output is shown.
By any chance is there any limit to passing data from controller to view?
In view if i use print_r($details[0]);
鉴于我是否使用print_r($details[0]);
or print_r($details[n]);
the result is printed. If print_r($details);
is used then page is just blank. What could be the problem?
try this in the model
public function Get_Details()
{
$query = "
SELECT
*
FROM
tablename
";
$result = $this->db->query($query);
return $result->result();
}
Have you tried this code :
Model
public function Get_Details()
{
$query = "
SELECT
*
FROM
tablename
";
return $this->db->query($query);
}
View
<?php
print_r($details->result());
?>
The result() function returns the query result as an array of objects, or an empty array on failure.
You will need to loop through it in your view to get the expected results.
You can look here for details: http://ellislab.com/codeigniter/user-guide/database/results.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.