Hi CI developers I am new to CI framework so request you guys to help me in splitting array values in my view page. I am able to print the query values in my view page in this way, for which I wrote the following code:
echo "<pre>";
print_r($showdata); //I am getting o/p in this way
Array
(
[results] => Array
(
[0] => Array
(
[id] => 205
[uid] => mh47
[profile_for] => self
[gender] => female
)
)
[count] => 1
[pages] => 1
)
Now I want to split these array values and count values and pages values so request you to help me. I tried it this way but I am not getting any output:
if (isset($data['showdata'])){
foreach ($showdata->result() as $key) {
<?php echo ($key->gender); echo $key['gender']; ?>
<?php
}
}
?>
below is my model page
$data['showdata'] = $this->searchresultss->login($per_page,$look,$age);
$this->load->view('searchresult',$data);
below is my model page
function login($per_page=3,$look,$age,$age_to,$age_from,$se_ct,$subsect,$coun_try, $sta_te, $ci_ty,$qualification)
{
$query="SELECT * FROM users";
$data=array();
$query=$this->db->query($query);
$data['results']=$query->result_array();
$data['count']=$query->num_rows();
$data['pages']=ceil($data['count']/3);
return $data;
when this works
echo "<pre>";
print_r($showdata);
Why am I not able to echo the array value. I am in a lot of confusion, so guys please help me. I am new to CI framework so I am unable to sort out the problem.
$data['showdata']
only exists in the controller, in the view you should access it like this:
if (isset($showdata)){ //...
Your foreach should probably look like this:
foreach($showdata['results'] as $k => $v){
echo $v['gender'];
}
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.