Hi Guys

i am developing a system in php using codeigniter framework, in this i retrived result from database

it stored in an variable and its var_dump result is like

var_dump($cat_data)

object(stdClass)#21 (4) {
  ["id"]=>
  string(1) "1"
  ["name"]=>
  string(8) "Computer"
  ["image"]=>
  string(1) "0"
  ["p_cat"]=>
  string(1) "0"
  }

when i try to fetch data from this using foreach loop with this coding

  foreach ($cat_data as $row_cat )
{

    echo $row_cat->id;

}

i gives message "Message: Trying to get property of non-object"

and when i try to use it like

echo $row_cat['id'] is says

Message: Illegal string offset 'id'

can somebody help me please i am confused

You dont need the foreach

just use

$cat_data->id
$cat_data->name
$cat_data->image
$cat_data->p_cat
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.