gpt4 book ai didi

codeigniter - 在 View codeigniter 中显示查询

转载 作者:行者123 更新时间:2023-12-04 02:45:04 24 4
gpt4 key购买 nike

假设来 self 的 Controller 的查询是 $query。
除了使用这种代码之外,如何显示数据?

foreach($query as $row){
echo $row->student_id;
}

除了这个因为查询只有一行
有什么方法可以像这样访问返回的数组?

$query['student_id'];

最佳答案

假设您的表格有以下字段

student_id and student_name

让您的模型或 Controller 只返回一行。

function get_first_student() {

$query = this->db->select('*')->from('student')-where('student_id','1')->limit(1);
$data['stuff'] = $query->row_array(); // or $query->row() which returns an object
$this->load->view('whatever',$data)

}

那么在你看来

<p>student name: <?= $stuff['student_name'] ?> </p>
<p>student id: <?= $stuff['student_id'] ?> </p>

关于codeigniter - 在 View codeigniter 中显示查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6309255/

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