Welcome Guest, Not a member yet? Register   Sign In
Multiple error messages while trying to display data from DB
#1

[eluser]sehummel[/eluser]
Here is my function. It is very simple.

Code:
function load_data() {

        $query = $this->db->query('SELECT * FROM configurations WHERE username="' . $this->session->userdata('username') . '"');
        return $query;
   }

My controller has this line of code:

Code:
$data['query'] = $this->configurations->load_data();

In my view, I tried:

Code:
foreach($query->result_array() as $row) {

echo $row->first;

}

But I get an error that I am trying to get a property of a non-object. Isn't the query being returned from the model as an object?

I tried:
Code:
foreach($query->result() as $row) {
but I get an error:
Code:
Message: Undefined property: stdClass::$first
#2

[eluser]Cristian Gilè[/eluser]
What are the fields name of the configurations table?

if you use result_array():

Code:
foreach($query->result_array() as $row)
{

echo $row['field_name_1'];
echo $row['field_name_2'];
....
....
echo $row['field_name_N'];
}

if you use result()

Code:
foreach($query->result() as $row)
{

echo $row->field_name_1;
echo $row->field_name_2;
....
....
echo $row->field_name_N;
}

substitute field_name_1, field_name_2, ....,....,field_name_N with the configurations table fields name.


Cristian Gilè




Theme © iAndrew 2016 - Forum software by © MyBB