【问题标题】:The word "Array" gets printed instead of the values of the rows打印单词“Array”而不是行的值
【发布时间】:2011-09-17 22:09:45
【问题描述】:

好的,我是 CI 和 MySQL 的新手。这是我的代码:

<?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;
    }   
}

}

?>

这将返回单词“Array”来代替行的值。我似乎无法弄清楚为什么。提前致谢。 :)

【问题讨论】:

    标签: php mysql codeigniter


    【解决方案1】:

    使用

    var_dump($row);
    

    而不是

    echo $row;
    

    如果您只想查看数组的值,可以执行以下操作

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

    【讨论】:

      【解决方案2】:

      $row 是一个数组。使用$row['column'] 访问单个列。要查看数组的样子,您可以使用print_r($row)var_dump($row)

      【讨论】:

        猜你喜欢
        • 2015-09-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-07
        • 1970-01-01
        • 2018-11-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多