FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Re: Transforming object properties?
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Transforming object properties? [message #177974] Wed, 09 May 2012 08:02
M. Strobel is currently offline  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.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: reading a newline from a properties file
Next Topic: Re: reading a newline from a properties file
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 04:48:54 GMT 2024

Total time taken to generate the page: 0.01976 seconds