Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The word "Array" gets printed instead of the values of the rows

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. :)

like image 253
Arvind Avatar asked Dec 08 '25 02:12

Arvind


2 Answers

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].", ";
like image 61
MoarCodePlz Avatar answered Dec 10 '25 16:12

MoarCodePlz


$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)

like image 45
knittl Avatar answered Dec 10 '25 16:12

knittl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!