我有这个数组我没有得到area_tutor,因为它的值为逗号
Array
(
[0] => stdClass Object
(
[tuitor_id] => 288
[mobile_tuitor] => 0123456789
[alt_mobile_tuitor] =>
[fullname_tuitor] =>
[gender_tuitor] => male
[city_tutor] => 2
[area_tutor] => 7,8,9
)
[1] => stdClass Object
(
[tuitor_id] => 287
[mobile_tuitor] => 2568798456
[alt_mobile_tuitor] =>
[fullname_tuitor] => sumit test new filed
[gender_tuitor] => male
[city_tutor] => 1
[area_tutor] => 3
)
[2] => stdClass Object
(
[tuitor_id] => 285
[mobile_tuitor] => 1452587658
[alt_mobile_tuitor] => 0789578469
[fullname_tuitor] => Sumit Nair
[gender_tuitor] => male
[city_tutor] => 1
[area_tutor] => 1,2,3,4
)
[3] => stdClass Object
(
[tuitor_id] => 273
[mobile_tuitor] => 0954652478
[alt_mobile_tuitor] =>
[fullname_tuitor] => vbvbbb
[gender_tuitor] => female
[city_tutor] => 1
[area_tutor] => 3
)
[4] => stdClass Object
(
[tuitor_id] => 225
[profile_title] =>
[mobile_tuitor] => 4557821212
[alt_mobile_tuitor] => 5445587112
[fullname_tuitor] => xyz
[gender_tuitor] => male
[city_tutor] => 4
[area_tutor] => 14
)
)
其中area_tutor有逗号的值,我从foeach循环中检索时没有得到我只得到了area_tutor的第一个元素,这就是我如何循环使用foreach循环
$this->db->select('*')->from('tuitor');
$this->db->order_by("tuitor_id", "desc");
$this->db->join('city_tuitor', 'tuitor.city_tutor = city_tuitor.city_id', 'left');
$this->db->join('area_tuitor', 'tuitor.area_tutor = area_tuitor.area_id', 'left');
$query=$this->db->get();
return $result = $query->result();
现在在视图中我只是循环遍历foreach循环
如果我这样打印,我会得到上面的aray 的print_r($结果);
但是当我试图回应当时的值时,我只获得了area_tutor的第一个值
<?php foreach($result as $r) { ?>
echo $r->tuitor_id;
echo $r->mobile_tuitor;
echo $r->city_tutor;
echo $r->area_tutor;
<?php } ?>
请帮助我如何获得area_tutor的所有值
答案 0 :(得分:2)
尝试使用简单方法打印值..
<?php
$result = $query->result_array();
foreach($result as $key=>$val)
{
echo $val['tuitor_id'];
echo $val['mobile_tuitor'];
echo $val['city_tutor'];
echo $val['area_tutor'];
}
?>
答案 1 :(得分:1)
尝试使用where_in()
$this->db->where_in();
Generates a WHERE field IN ('item', 'item') SQL query joined with AND if appropriate
$area_tutor= array('1', '2', '3');
$this->db->where_in('area_tutor', $area_tutor);
// Produces: WHERE area_tutor IN ('1', '2', '3')