gpt4 book ai didi

php - 显示 $query->result();

转载 作者:行者123 更新时间:2023-11-29 04:46:26 24 4
gpt4 key购买 nike

我在使用 codeigniter 中的 foreach 循环显示查询结果时遇到了一些问题。这是我的 Controller :

function viewall()
{
$this->load->model('all');
$data['query'] = $this->all->viewall();
$this->load->view('all', $data);
}

整个模型文件:

<?php
class All extends CI_Model
{

function insert_into_db()
{
$data = array('Error' => $this->input->post('f1'),
'Solution' => $this->input->post('f2')
);
$this->db->insert('Errors', $data);
}

function viewall()
{
$query = $this->db->select("Error, Solution")->from("Errors")->get();
return $query->result();
}

我的看法(我认为问题出在哪里)

<table class="table table-striped">
<thead>
<tr>
<td><h3>Error</h3></td>
<td><h3>Solution</h3></td>
</tr>
</thead>
<tbody>
<?php foreach ($query->result_array() as $entry) ?>
<tr>
<td><?php echo $entry->Error; ?></td>
<td><?php echo $entry->Solution;?></td>
</tr>
<?php endforeach ?>
</tbody>
</table>

最佳答案

Controller :

function viewall()
{
$this->load->model('all');
$data['results'] = $this->all->viewall();
$this->load->view('all', $data);
}

型号:

function viewall()
{
$query = $this->db->select("Error, Solution")->from("Errors")->get();
return $query->result();
}

查看:

<table class="table table-striped">
<thead>
<tr>
<td><h3>Error</h3></td>
<td><h3>Solution</h3></td>
</tr>
</thead>
<tbody>
<?php foreach ($results as $entry): ?>
<tr>
<td><?php echo $entry->Error; ?></td>
<td><?php echo $entry->Solution;?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>

关于php - 显示 $query->result();,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18266748/

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