Home »
Imported messages »
comp.lang.php »
Re: Transforming object properties?
Re: Transforming object properties? [message #177974] |
Wed, 09 May 2012 08:02 |
M. Strobel
Messages: 386 Registered: December 2011
Karma: 0
|
Senior Member |
|
|
Am 09.05.2012 01:44, schrieb Mike:
> I need an array of objects that looks like this:
>
> $items[$i]->name
> ->new_amount
> ->old_amount
>
> The data would look like this:
>
> name new_amount old_amount
> John 500.00 200.00
> Sue 15.00 <NULL>
> Frank 254.00 <NULL>
> Max <NULL> 28.00The data would look like this:
>
> But the results of my sql query comes back as:
>
> $items[$i]->name
> ->type
> ->amount
>
> name type amount
> ----------------------------------
> John new_amount 500.00
> John old_amount 200.00
> Sue new_amount 15.00
> Frank new_amount 254.00
> Max old_amount 28.00
>
> Is there a reasonable way to accomplish this?
$stmt = $pdo->query("select name, new_amount, old_amount from table1");
if ($stmt) {
$res = $stmt->fetchAll(PDO::FETCH_CLASS);
} else {
trigger_error('statement failed, see error messages',E_USER_ERROR);
}
/Str.
|
|
|
Goto Forum:
Current Time: Sat Nov 23 04:48:54 GMT 2024
Total time taken to generate the page: 0.01976 seconds