代码noob中的错误无法修复它们

use*_*150 0 php variables foreach codeigniter

我正在开发一个显示数据库表中数据的小应用程序.我得到2个错误,不知道为什么会有,我无法弄清楚,因为我仍然是一个菜鸟.我猜它有点蠢,请帮忙.

错误

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: querys


Severity: Warning

Message: Invalid argument supplied for foreach()
Run Code Online (Sandbox Code Playgroud)

这些错误位于我的视图页面中.

视图

    <?php foreach ($queries as $row): ?>
    <table>

       <th>Name</th>
       <th>Surname</th>
       <th>phone</th>
       <th>email</th>

       <td><?php echo $row->name; ?></td>
       <td><?php echo $row->surname; ?></td>
       <td><?php echo $row->phone; ?></td>
       <td><?php echo $row->email; ?></td>

   </table>  
    <?php endforeach; ?>
Run Code Online (Sandbox Code Playgroud)

CONTROLLER

  function display($offset = 0)
    {
           $limit = 20;
            $this->load->model('info_model');

            $results = $this->info_model->search($limit, $offset);

            $data['queries'] = $results['rows'];
            $data['num_results'] = $results['num_rows'];


            $this->load->view('info_view',$data);


    }
Run Code Online (Sandbox Code Playgroud)

模型

 function search ($limit, $offset){

          //results query 
          $q = $this->db->select('ID, name, surname, phone, email');
          $this->db->from('tblinfo');
          $this->db->limit($limit, $offset);

          $ret['rows'] = $q->get()->result();
          //count query
          $q = $this->db->select('COUNT(*) as count', FALSE )
          ->from('tblinfo');

          $tmp = $q->get()->result();

          $ret['num_rows'] = $tmp[0]->count;
          return $ret;
      }
Run Code Online (Sandbox Code Playgroud)

编辑

我通过插入修复了foreach错误

   <?php if(is_array($queries)): ?>
   <?php endif; ?>
Run Code Online (Sandbox Code Playgroud)

我得到的唯一错误是

   A PHP Error was encountered

    Severity: Notice

    Message: Undefined variable: queries
Run Code Online (Sandbox Code Playgroud)

Dam*_*rsy 5

$data['query'] = $results['rows'];
Run Code Online (Sandbox Code Playgroud)

应该

$data['querys'] = $results['rows']; // although correct spelling is "queries"
Run Code Online (Sandbox Code Playgroud)

然后,您可以$querys在视图中访问.