Php 找不到数据时获取foreach循环错误
我在没有结果集的情况下获得此Arry:Php 找不到数据时获取foreach循环错误,php,codeigniter,Php,Codeigniter,我在没有结果集的情况下获得此Arry: Array ( [data] => Array ( [res] => ) ) Array ( [data] => Array ( [res] => 1 [rows] => Array ( [0] => stdC
Array
(
[data] => Array
(
[res] =>
)
)
Array
(
[data] => Array
(
[res] => 1
[rows] => Array
(
[0] => stdClass Object
(
[aprtid] => 11
[bldcode] => a
[buldname] => cd
[aptno] => 901
[aptcore] => 2
[aptfloor] => 2
[buldsiteid] => 11
[rsdntname] => Gaurav
[rsdntemail] => Gaurav@gmail.com
[rsdntphone] => 9891110987
[rsdntpic] => 1498461013.jpg
[accessperson] => Ankit
)
After that i did this to recieved data :
<?php
$value=$data['rows'];
?>
its giving me that array
Array
(
[0] => stdClass Object
(
[aprtid] => 11
[bldcode] => A_12
[buldname] => BT Tower
[aptno] => 901
[aptcore] => 2
[aptfloor] => 2
[buldsiteid] => 11
[rsdntname] => Pankaj
[rsdntemail] => pankaj@gmail.com
[rsdntphone] => 9876543219
[rsdntpic] =>
[accessperson] => Ankit
)
for accessing this data i used foreach cos there can be multiple records so i used that.
<?php
foreach ($value as $data) {
?>
<tr>
<td> <img src='<?=BASE_URL?>assets/images/<?= (!empty($data->rsdntpic)) ? $data->rsdntpic : '' ?>'> </td>
<td> <?= (!empty($data->name)) ? $data->name : 'No Records' ?> </td>
<td> <?=(!empty($data->email)) ? $data->email : 'No Records' ?></td>
<td> <?= (!empty($data->phone)) ? $data->phone : 'No Records' ?> </td>
</tr>
<?php } ?>
当有结果集时,我将获得此Arry:
Array
(
[data] => Array
(
[res] =>
)
)
Array
(
[data] => Array
(
[res] => 1
[rows] => Array
(
[0] => stdClass Object
(
[aprtid] => 11
[bldcode] => a
[buldname] => cd
[aptno] => 901
[aptcore] => 2
[aptfloor] => 2
[buldsiteid] => 11
[rsdntname] => Gaurav
[rsdntemail] => Gaurav@gmail.com
[rsdntphone] => 9891110987
[rsdntpic] => 1498461013.jpg
[accessperson] => Ankit
)
After that i did this to recieved data :
<?php
$value=$data['rows'];
?>
its giving me that array
Array
(
[0] => stdClass Object
(
[aprtid] => 11
[bldcode] => A_12
[buldname] => BT Tower
[aptno] => 901
[aptcore] => 2
[aptfloor] => 2
[buldsiteid] => 11
[rsdntname] => Pankaj
[rsdntemail] => pankaj@gmail.com
[rsdntphone] => 9876543219
[rsdntpic] =>
[accessperson] => Ankit
)
for accessing this data i used foreach cos there can be multiple records so i used that.
<?php
foreach ($value as $data) {
?>
<tr>
<td> <img src='<?=BASE_URL?>assets/images/<?= (!empty($data->rsdntpic)) ? $data->rsdntpic : '' ?>'> </td>
<td> <?= (!empty($data->name)) ? $data->name : 'No Records' ?> </td>
<td> <?=(!empty($data->email)) ? $data->email : 'No Records' ?></td>
<td> <?= (!empty($data->phone)) ? $data->phone : 'No Records' ?> </td>
</tr>
<?php } ?>
在将数据迭代为isset$data['rows']之前,使用php isset检查该值是否已设置且不为null
使用空函数检查数组是否有值
<?php
if (!empty($data['rows'])) {
}
?>
你试过在foreach循环中传递$data['rows']吗?使用isset检查该值是否存在,然后作为isset$data['rows']迭代你的数据。你能更新我的问题吗???@B2725我做了,但得到了相同的错误检查我的答案我们现在不需要在php中使用isset的if吗!!