Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 找不到数据时获取foreach循环错误_Php_Codeigniter - Fatal编程技术网

Php 找不到数据时获取foreach循环错误

Php 找不到数据时获取foreach循环错误,php,codeigniter,Php,Codeigniter,我在没有结果集的情况下获得此Arry: Array ( [data] => Array ( [res] => ) ) Array ( [data] => Array ( [res] => 1 [rows] => Array ( [0] => stdC

我在没有结果集的情况下获得此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 } ?>
当有结果集时,我将获得此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吗!!