Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.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 记录在查看页面上显示两次_Php_Mysql_Codeigniter 3 - Fatal编程技术网

Php 记录在查看页面上显示两次

Php 记录在查看页面上显示两次,php,mysql,codeigniter-3,Php,Mysql,Codeigniter 3,我正在使用CodeIgniter。我在查看页面上得到两条记录 $data['upcomingForsecondary']=$this->Access_model->upcomingsecondary($data['getLogininfo']->customer_id); 获取输出 Array ( [0] => stdClass Object ( [member_id] => 337 [fir

我正在使用CodeIgniter。我在查看页面上得到两条记录

$data['upcomingForsecondary']=$this->Access_model->upcomingsecondary($data['getLogininfo']->customer_id);
获取输出

Array
(
    [0] => stdClass Object
        (
            [member_id] => 337
            [first_name] => zxs
            [middle_name] => 
            [last_name] => asd
            [email] => qwe@gmail.com
            [dob] => 22-04-1984
            [phone] => 1231231231
            [landline] => 
            [membershipForTheYear] => 2018-2019
        )

    [1] => stdClass Object
        (
            [member_id] => 209
            [first_name] => sdf
            [middle_name] => 
            [last_name] => asd
            [email] => asdas@gmail.com
            [dob] => 24-07-1982
            [phone] => 1231231231
            [landline] => 
            [membershipForTheYear] => 2018-2019
        )

)
现在,我使用foreach获得了该模型今年的通过会员资格

控制器代码

$data['upcomingForsecondary']=$this->Access_model->upcomingsecondary($data['getLogininfo']->customer_id);

foreach ($data['upcomingForsecondary'] as $key => $sec_m_id) {
  $secClubfees[]=$this->Access_model->getfeesFornewyear($sec_m_id->membershipForTheYear);
 }
 $data['newFees'] = $secClubfees;
I tried on view like 

 foreach ($upcomingForsecondary as $key => $secPersonalInfo) {
   /*Displaying personal information which is dislaying perfeclty*/

   foreach ($newFees as $key => $value) {
     foreach ($value as $key => $rows) {

      /*getting issue here. I a getting the twice output*/


              }

      }


}
**打印($data['newFees'])输出**

Array
(
    [0] => Array
        (
            [0] => stdClass Object
                (
                    [clubMembershipFees_id] => 1
                    [clubDuration] => 2019-2020
                    [clubPrimaryMemberFees] => 100
                    [startCutoffDate] => 16-02-2019
                    [endCutoffDate] => 31-03-2019
                    [is_clubFeesActive] => 1
                )

        )

    [1] => Array
        (
            [0] => stdClass Object
                (
                    [clubMembershipFees_id] => 1
                    [clubDuration] => 2019-2020
                    [clubPrimaryMemberFees] => 100
                    [startCutoffDate] => 16-02-2019
                    [endCutoffDate] => 31-03-2019
                    [is_clubFeesActive] => 1

                )

        )

)
查看代码

$data['upcomingForsecondary']=$this->Access_model->upcomingsecondary($data['getLogininfo']->customer_id);

foreach ($data['upcomingForsecondary'] as $key => $sec_m_id) {
  $secClubfees[]=$this->Access_model->getfeesFornewyear($sec_m_id->membershipForTheYear);
 }
 $data['newFees'] = $secClubfees;
I tried on view like 

 foreach ($upcomingForsecondary as $key => $secPersonalInfo) {
   /*Displaying personal information which is dislaying perfeclty*/

   foreach ($newFees as $key => $value) {
     foreach ($value as $key => $rows) {

      /*getting issue here. I a getting the twice output*/


              }

      }


}
查看我得到的输出

first member name
fees details
fees details

second member name
fees details
fees details
我使用了多个foreach,这就是问题所在。我认为在查看页面或控制器上存在一些问题


你能帮我解决这个问题吗?

不知道它是关于什么的,也不知道codeigniter:)的线索

在这里,您将两个结果放在一个数组中,并失去与
$data['upcomingForsecondary']
中对象的关系

然后在视图中

foreach ($upcomingForsecondary as $key => $secPersonalInfo) {
    // Displaying personal information
    foreach ($newFees as $key => $value) {
        // show the rows
    }
}
newFees
中循环两次这两个结果(在
$upcomingForsecondary
中每个对象循环一次)

因此,您需要使用
$key
$secPersonalInfo
将内循环与外循环关联起来。我可以提出三种方法

#我希望钥匙是一样的: #2确保钥匙相同: 然后使用#1中的视图代码

#3.结果: 控制器:

foreach ($data['upcomingForsecondary'] as $key => $sec_m_id) {
    $sec_m_id->newFees
        = $this->Access_model->getfeesFornewyear($sec_m_id->membershipForTheYear);
}
在这种情况下,您不需要
$data['newFees']

视图:


就我个人而言,我更喜欢#3

到目前为止,您是如何发现错误的?@NicoHaase,谢谢您的回复。不管我怎么想,我都在问题中加了一句。我没有得到错误。两次获取记录谢谢回答。请给我一些时间检查。在#2中,我是否应该添加$data['newFees]=$secClubfees?@user9437856 Yes。。但我刚刚意识到我的视野中有一个bug。现在应该修好了。用
foreach(
forecondary[$key]升级为$key=>$rows)
替换为
foreach(
newFees[$key]升级为$key=>$rows)
让我再试一次。给我一些time@user9437856代码中还存在另一个bug,这在代码中可能并不重要。但是您不应该从内部循环的外部循环覆盖
$key
。我将它们重命名为
$key1
$key2
。在实际代码中,我会使用更合适的变量名。
foreach ($data['upcomingForsecondary'] as $key => $sec_m_id) {
    $sec_m_id->newFees
        = $this->Access_model->getfeesFornewyear($sec_m_id->membershipForTheYear);
}
foreach ($upcomingForsecondary as $key1 => $secPersonalInfo) {
    // Displaying personal information
    foreach ($secPersonalInfo->newFees as $key2 => $rows) {
        // show the row
    }
}