[英]how to split array values in view page in codeigniter
Hi CI developers I am new to CI framework so request you guys to help me in splitting array values in my view page. 尊敬的CI开发人员:我是CI框架的新手,所以请大家帮助我在我的视图页面中拆分数组值。 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.
我是CI框架的新手,所以我无法解决问题。
$data['showdata']
only exists in the controller, in the view you should access it like this: $data['showdata']
仅存在于控制器中,在视图中应按以下方式访问它:
if (isset($showdata)){ //...
Your foreach should probably look like this: 您的foreach应该看起来像这样:
foreach($showdata['results'] as $k => $v){
echo $v['gender'];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.