result_array 值未显示在 codeigniter 中的 foreach 循环内

我只是使用 Codeigniter 触发一个选择查询,其中在我使用print_r函数时显示所有值,但是当我使用foreach循环时没有显示值我不知道问题是什么?我该如何解决这个问题?


$this->db->select('*');

    $this->db->from('user_detail');

    $where = "jid='".$jid_final."' and cid='".$cid_final."' and offer='1'";

    $this->db->where($where);

    $sql_user = $this->db->get();

    $result_user = $sql_user->result_array();

    print_r($result_user);

    foreach($result_user as $row_user)

    {


        $user_data = '<tr>

                        <td class="td">'.$row_user['uid'].'</td>

                        <td class="td">'.$row_user['fname'].' '.$row_user['lname'].'</td>

                        <td class="td">'.$row_user['email'].'</td>

                        <td class="td">'.$row_user['phone'].'</td>

                    </tr>';

    }

    echo $user_data;


暮色呼如
浏览 160回答 2
2回答

开心每一天1111

使用下面的查询,需要检查表中是否有数据,然后将其传递给 foreach 循环。&nbsp;$user_data = '';&nbsp;$this->db->select('*');&nbsp; &nbsp; $where = "jid='".$jid_final."' and cid='".$cid_final."' and offer='1'";&nbsp; &nbsp; $this->db->where($where, NULL, FALSE);&nbsp; &nbsp; $result_user = $this->db->get('user_detail')->result_array();&nbsp; &nbsp; if($result_user) {&nbsp; &nbsp; foreach($result_user as $row_user)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; $user_data .= '<tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td class="td">'.$row_user['uid'].'</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td class="td">'.$row_user['fname'].' '.$row_user['lname'].'</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td class="td">'.$row_user['email'].'</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td class="td">'.$row_user['phone'].'</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </tr>';&nbsp; &nbsp; }&nbsp; &nbsp; &nbsp;echo $user_data;&nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp;echo "no data found";&nbsp; &nbsp; }

阿波罗的战车

尝试将值与 .$user_data = '';if(isseet($result_user) && count($result_user) > 0){foreach($result_user as $row_user){&nbsp; &nbsp; $user_data .= '<tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td class="td">'.$row_user['uid'].'</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td class="td">'.$row_user['fname'].' '.$row_user['lname'].'</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td class="td">'.$row_user['email'].'</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td class="td">'.$row_user['phone'].'</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </tr>';}&nbsp; &nbsp; echo $user_data;}else{&nbsp; &nbsp; echo 'Record not found';}
打开App,查看更多内容
随时随地看视频慕课网APP