By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,949 Members | 1,824 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,949 IT Pros & Developers. It's quick & easy.

Modifying MySQL Result - but not the DB

P: n/a
Hi,

How can I modify a MySQL data set returned by mysql_query? I am
basically doing a while loop over the rows, changing one field, and
then doing a mysql_data_seek back to the beginning of the set before
returning it. However, later calls to mysql_fetch_assoc still return
the orginal data, meaning that (I assume) I am changing a copy of the
data rather than the result set itself. Taking the reference (i.e.
$record =& mysql_fetch_assoc($result);) did not help.

I have read a large quantity of the posts in the php.net site,
googled, and read my PHP books - but have come up short on this one.

Yes, I know it's better to simply modify the DB. However, I'm working
with an existing code base which is very complicated, and want to
cherry pick one very well tested feature by making a change in the
result set only under special circumstances.

Thanks,
Ed Eichman
Cambrils, Spain
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Ed Eichman wrote:
Hi,

How can I modify a MySQL data set returned by mysql_query? I am
basically doing a while loop over the rows, changing one field, and
then doing a mysql_data_seek back to the beginning of the set before
returning it.


Are you doing the same calc to a field in every row? Or is there an "if"
involved. Anyway, why not try to put the "logic" into the sql statement that
creates the recordset. Look at the MySQL documentation on how to use an
embeded "iif" statement. That might be the best solution. You can do a hell
of a lot of logic in SQL if you learn how.

The other solution would be to get the result set into an array or maybe even
a temp table and then bounce down it and do what you want to do.

Al
Adams-Blake Company, Inc.
***
JAYA123 - the new web-based total-office system for the
small biz. Order entry, billing, bookkeeping, etc. for $14.95
a month. Everyone says "It's cool as a moose!!"
See why at:http://www.jaya123.com ('ja-eye-ah' means
'victory' in Sanskrit.)
***

Jul 17 '05 #2

P: n/a
Hi Al,

Thanks for the quick answer...
Are you doing the same calc to a field in every row? Or is there an "if"
involved. Anyway, why not try to put the "logic" into the sql statement that
creates the recordset. Look at the MySQL documentation on how to use an
embeded "iif" statement. That might be the best solution. You can do a hell
of a lot of logic in SQL if you learn how.
I'll check this out.
The other solution would be to get the result set into an array or maybe even
a temp table and then bounce down it and do what you want to do.


Not possible - the "downstream" code uses the query result - moving it
to an array would break the downstream code.

Thanks,
Ed
Jul 17 '05 #3

P: n/a
On 13 Jun 2004 00:05:22 -0700, ei*******@hotmail.com (Ed Eichman)
wrote:
The other solution would be to get the result set into an array or maybe even
a temp table and then bounce down it and do what you want to do.


Not possible - the "downstream" code uses the query result - moving it
to an array would break the downstream code.


so a temporary table could do the trick. Just pass the sql statement
refering to the temporary table.

This will work only, id your "downstream" code will use the temporary
table right away, without a new connection to the database, because
the temporary will be erased after the connection is lost.

Regards

Marian

--
Tipps und Tricks zu PHP, Coaching und Projektbetreuung
http://www.heddesheimer.de/coaching/
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.