Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 未定义变量:结果_Php_Codeigniter_Undefined - Fatal编程技术网

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();
    }
    

模型公共函数show(){$query=$this->db->get('text');return$query->result();}控制器公共函数inf(){$this->load->model('addm');$data['results']=$this->addm->show();$this->load->view('backend/first',$data);}型号//我还有这个error@zeko50请告诉我您得到的错误..并检查上述代码遇到PHP错误严重性:注意消息:未定义变量:结果文件名:backend/first.PHP行号:74@zeko50请在您的视图中用我的代码更新您的代码file@zeko50我已经更新了上面的代码,请检查现在