gpt4 book ai didi

php - 传递给 Controller ​​的对象数组, View 并将它们作为列表显示在 View 中

转载 作者:行者123 更新时间:2023-11-30 22:00:30 25 4
gpt4 key购买 nike

我必须从名为 user_login 的表中检索多个列并将其显示在 View 中。我在一系列对象中收到它,但在显示数据时遇到问题。我的模型是

$this->db->select('username,country,designation');
$this->db->from('user_login');

$this->db->join('friends','friends.friend_id=user_login.id');



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

我的查询转储是

CI_DB_mysqli_result Object ( [conn_id] => mysqli Object ( [affected_rows] => 5 [client_info] => mysqlnd 5.0.11-dev - 20120503 - $Id: 15d5c781cfcad91193dceae1d2cdd127674ddb3e $ [client_version] => 50011 [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => [error_list] => Array ( ) [field_count] => 3 [host_info] => Localhost via UNIX socket [info] => [insert_id] => 0 [server_info] => 5.5.5-10.1.19-MariaDB [server_version] => 50505 [stat] => Uptime: 4836 Threads: 1 Questions: 151 Slow queries: 0 Opens: 19 Flush tables: 1 Open tables: 13 Queries per second avg: 0.031 [sqlstate] => 00000 [protocol_version] => 10 [thread_id] => 41 [warning_count] => 0 ) [result_id] => mysqli_result Object ( [current_field] => 0 [field_count] => 3 [lengths] => [num_rows] => 5 [type] => 0 ) [result_array] => Array ( ) [result_object] => Array ( ) [custom_result_object] => Array ( ) [current_row] => 0 [num_rows] => [row_data] => )

请告诉我什么应该传递给 Controller ​​,什么应该传递给 veiw。我知道如何使用 foreach 循环显示数组对象中的元素。但无论我尝试什么,它都会在 View 中给出未定义的错误。我的 Controller 是

$result=$this->Main_Model->display_following($user_id);






$this->load->view('following',$result);

最佳答案

您必须使用 result_array() 函数将结果存储在变量中

<?php

$this->db->select('username,country,designation');
$this->db->from('user_login');

$this->db->join('friends','friends.friend_id=user_login.id');
$query = $this->db->get();
$result = $query->result_array();

关于php - 传递给 Controller ​​的对象数组, View 并将它们作为列表显示在 View 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43568314/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com