Php 未定义变量:结果
模型Php 未定义变量:结果,php,codeigniter,undefined,Php,Codeigniter,Undefined,模型 public function show() { $query = $this->db->get('text'); return $query->result(); } 2.控制器 public function inf() { $this->load->model('addm'); $data['results'] = $this->addm->show($query);
public function show()
{
$query = $this->db->get('text');
return $query->result();
}
2.控制器
public function inf()
{
$this->load->model('addm');
$data['results'] = $this->addm->show($query);
$this->load->view('backend/first',$data);
}
3.观点
我试图从数据库中获取数据,但无法解决此错误:
未定义变量:结果
<?php
echo"<td>";
if (is_array($result)) {
foreach ($result() as $row) {
$id = $row->id;
$words = $row->words;
}
}
echo "</td>";
?>
很少有事情
- 在您的模型中,函数show不需要任何参数
- 从
$this->addm->show()中删除
代码>如不需要$query
- 在视图中,变量应为结果而不是结果
// controller public function inf() { $this->load->model('addm'); $data['results'] = $this->addm->show(); $this->load->view('backend/first', $data); } // view if (!empty($results)) { foreach($results as $row) { $id = $row->id; $words = $row->words; } } // model public function show() { $query = $this->db->get('text'); return $query->result(); }