【发布时间】:2019-08-19 04:21:21
【问题描述】:
使用查询我得到数组中的结果,我想在一个数组中获取这些数据, 我得到如下方式的结果
Array
(
[0] => stdClass Object
(
[id] => 2
[full_name] => amit sharma
)
[1] => stdClass Object
(
[id] => 1
[full_name] => amit
)
)
我尝试使用以下代码但不适合我,我错了,这是我的代码
$sql = "//select query";
$result= $this->db->query($sql)->result();
$total=count($result);
if($total>0)
{
$data=array();
foreach($result as $records)
{
$data[]=$records;
}
echo "<pre>";print_R($data);
}
【问题讨论】:
-
查看您想要访问的数组的示例会很有用
-
你可以使用
result_array()而不是result()然后你会得到一个纯数组的查询结果 -
只有数据?因为数组中不能有重复的键。
-
但对我不起作用你的意思是它正在崩溃吗?你的意思是它没有生成你想要的数组吗?请记住,我们不是在看着您,只有在您向我们提供足够的信息以提供帮助时,我们才能提供帮助
-
@MasivuyeCokile:如果我使用 result_array,那么数据来自数组内的数组
标签: php mysql arrays codeigniter