Modifying MySQL Result - but not the DB

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ed Eichman

    Modifying MySQL Result - but not the DB

    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_ass oc 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_ass oc($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
  • A-B C.

    #2
    Re: Modifying MySQL Result - but not the DB

    Ed Eichman wrote:
    [color=blue]
    > 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.[/color]

    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.)
    ***

    Comment

    • Ed Eichman

      #3
      Re: Modifying MySQL Result - but not the DB

      Hi Al,

      Thanks for the quick answer...
      [color=blue]
      > 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.[/color]

      I'll check this out.
      [color=blue]
      > 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.[/color]

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

      Thanks,
      Ed

      Comment

      • Marian Heddesheimer

        #4
        Re: Modifying MySQL Result - but not the DB

        On 13 Jun 2004 00:05:22 -0700, eichmaned@hotma il.com (Ed Eichman)
        wrote:
        [color=blue][color=green]
        >> 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.[/color]
        >
        >Not possible - the "downstream " code uses the query result - moving it
        >to an array would break the downstream code.[/color]

        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 Projektbetreuun g
        Da ich mich seit einiger Zeit aus der Programmierung von Websites zurückgezogen habe, sind meine Tutorials und Schulungsinhalte nicht mehr länger verfügbar, da sie inzwischen veraltet sind.

        Comment

        Working...