Forum Moderators: coopster

Message Too Old, No Replies

Formatting every SQL result

         

optik

6:11 pm on Aug 28, 2009 (gmt 0)

10+ Year Member



I need to apply a function to every result I get from an SQL query but don't want to do this to each result individually, how can I apply a function to every result in one go?

Demaestro

7:39 pm on Aug 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Check your db manual for Triggers and functions.

A trigger can be added to any table in your db, you can define the trigger to run a function, before or after, an update, a select, or insert statement.

What you would want is the function to run after a select statement pass the data to the function... alter it to your liking then return that formatted data to the method performing the query.

optik

8:22 pm on Aug 28, 2009 (gmt 0)

10+ Year Member



I need to use a PHP function though not an SQL function.

coopster

9:42 pm on Aug 28, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



If the result set is fetched as an array you can use something like array_map [php.net] or some other array processing function to "walk" through it.

optik

9:58 am on Sep 2, 2009 (gmt 0)

10+ Year Member



I had a look at array map but couldn't get a result from it, seemed to be something about the way the fetched SQL array was formatted, unless I was doing something wrong?