【问题标题】:How can I fetch multiple rows from MySQL and display individually in view in codeigniter如何从 MySQL 中获取多行并在 codeigniter 中单独显示
【发布时间】:2016-08-06 20:13:59
【问题描述】:

我想在视图中获取多行但不是作为 array() 而是在不同的容器中单独获取。我搜索了不同的代码但都失败了,我使用以下代码单独获取数据但得到错误Undefined Variable: row

  <?php $query = $this->db->get("content");
 for($i=1;$i <= $query -> num_rows(); ++$i){
 $data[$i]['c_id'] = $query -> $row($i) -> c_id;
 $data[$i]['con'] = $query -> $row($i)-> c_content;
 $data[$i]['img'] = $query -> $row($i)-> c_image;
 $data[$i]['link'] = $query -> $row($i)-> c_link;
 $data[$i]['heading'] = $query -> $row($i)-> c_heading;
     } 
// for echo 3rd value of data row
echo $data[3]['con'];  
?>

【问题讨论】:

    标签: php mysql codeigniter mysqli fetch


    【解决方案1】:

    $row($i) 中删除$;您需要使用它的row()

    <?php
     $query = $this->db->get("content");
     for($i=0;$i < $query->num_rows(); ++$i){
     $data[$i]['c_id'] = $query->row($i)->c_id;
     $data[$i]['con'] = $query->row($i)->c_content;
     $data[$i]['img'] = $query->row($i)->c_image;
     $data[$i]['link'] = $query->row($i)->c_link;
     $data[$i]['heading'] = $query->row($i)->c_heading;
         } 
    // for echo 3rd value of data row
    echo $data[3]['con'];  
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-09
      • 1970-01-01
      • 2018-07-26
      • 1970-01-01
      • 2012-01-26
      • 1970-01-01
      • 2013-01-26
      相关资源
      最近更新 更多