The word “Array” gets printed instead of the values of the rows

吃可爱长大的小学妹 提交于 2020-01-19 17:16:13

问题


Okay,i'm a newbie to CI and MySQL. This is my code:

<?php
class Trail2 extends CI_Controller{

public function boo() {

    $this->load->database();
    $this->load->helper('html');
    $ret="SELECT * from posts";
    $query=$this->db->query($ret);
    foreach($query->result_array() as $row)
    {
        echo br(1);
        echo $row;
    }   
}

}

?>

and this returns the word "Array" in place of the values of the rows. I cant seem to figure out why though. Thanks in advance. :)


回答1:


use

var_dump($row);

instead of

echo $row;

and if you just want to see the values of the array you can do something like the following

for ($var = 0; $var < sizeof($row); $var++) echo $row[$var].", ";



回答2:


$row is an array. use $row['column'] to access a single column. to see what the array looks like, you can use print_r($row) or var_dump($row)



来源:https://stackoverflow.com/questions/6398623/the-word-array-gets-printed-instead-of-the-values-of-the-rows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!