Newbie: Array of objects iteration

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello all,

I'm grabbing all records from a table using:

$records = $stmt->fetchAll(PDO::FETCH_OBJ);
return $records;


In order to display the values we can do:


foreach ($records as $record)
{			
		echo $record->id;
		echo $record->name;
}


However, I'd like to grab, also, the *column names*.

I've tried:

foreach ($records as $column=>$value)
{
	echo "$column is $value\n";
}

But I get:
"Catchable fatal error: Object of class stdClass could not be converted to
string"



Can I have your help on how can I properly get the column values?

Regards,
Márcio


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux