Andy Smith Wed Apr 18 07:33:45 -0400 2012

Subject: getting all rows from a result

edit: solved it.

hi!

I have a table with over 30 fields and I would like to echo out all the values as key=>value pairs after performing a search that returns one result. Is there a way to do this in a loop or something like that or do I really have to type it like this?

$p = Person::first();

echo 'id: '.$p->id;
echo 'name: '.$p->name;
echo 'gender: '.$p->gender;
etc.

EDIT: I think I got it now, but it throws me an exception when i encounter an object of ActiveRecord/DateTime. How do I work with that? Here's what I did:

$p = Partner::find($id);
$partner = $p->attributes();
foreach ($partner as $key => $value) {
echo $key . ':' . $value;
}

The exception when a Date occurs:

Catchable fatal error: Object of class DateTime could not be converted to string

thank you :)

edit: solved it.