-1

我收到此错误,

为 foreach() 提供的参数无效;未定义的变量:行............第 13 行视图中的错误......

请帮助我..我不知道错误在哪里

1.控制器

function customer_area() {

  $this->load->model('cus_model');

  $data['rows']=$this->cus_model->cusall();

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

}

2.型号

function cusall() {     
  $q = $this->db->get('customer');        
  $this->db->select('*');
  if($q->num_rows()>0) {    
    foreach($q->result() as $rows){      
      $data[]=$rows;
    }
    return $data;
  }
}`

3.views

<table border="1" height="200" width="200" bordercolor="#003366">
      <tr><th>ID</th></td><th>NAME</th><th>Type</th><th>Address</th><th>Mobile</th><th>Skype_Id</th><th>Email</th><th colspan="2">Actiom</th></tr>

      foreach($rows as $r)

    {
      echo "<tr>";
      echo "<td>". $r->id ."</td>";
      echo "<td>". $r->name ."</td>";
      echo "<td>". $r->type ."</td>";
      echo "<td>". $r->address ."</td>";
      echo "<td>". $r->mobile ."</td>";
      echo "<td>". $r->skype_id ."</td>";
      echo "<td>". $r->email ."</td>";
      echo "<td>". anchor('customer/input/'.$r->id,'Edit') ."</td>";    
      echo "<td>". anchor('customer/del/'.$r->id,'Delete') ."</td>";
      echo "</tr>"; 
      echo "<br>"; 
      }


      ?>
      </table>
4

1 回答 1

1

在您的模型中,返回 $q->result() 而不是循环遍历并将行放入数组中。

实际上,您几乎可以将其简化为:

新功能:

function cusall()       
{
    $q = $this->db->get('customer');
    return $q->result();
}
于 2012-06-22T19:20:36.143 回答