Page 1 of 1

Saving the previous value from mysql query

Posted: Fri Mar 30, 2007 4:55 am
by chasingSol
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello All,

How do i save the previous value from mysql, so that i could keep track of its change between the current value and the one i stored?

Here is my code

Code: Select all

$res = mysql_query("SELECT DISTINCT userid, UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(MIN(started)) AS seeded_for, seed_time FROM peers, users WHERE seeder = 'yes' AND userid= " . $CURUSER["id"] . " GROUP BY userid") or sqlerr(__FILE__, __LINE__);
        if (mysql_num_rows($res) > 0) {
                while ($arr = mysql_fetch_assoc($res)) {
                        if ($arr["seeded_for"] < $arr["seed_time"]) {
                                $dummy = $arr["seeded_for"];  //I want this variable to be the one that saves the previous value of the seeded_for
                                mysql_query("UPDATE users SET seed_time = seed_time + $dummy WHERE id IN (SELECT DISTINCT userid FROM peers WHERE seeder = 'yes') = $arr[userid]") or sqlerr(__FILE__, __LINE__);
                        }
                }
        }
In this code, i want the changement that is made on seeded_for from the query to be added to the seed_time. If the code is used like this, seed_time adds the whole seeded_for value to it, not the changement in the seeded_for.

I want to use $dummy to store the previous value of seeded_for (or track) the changement that is made on seeded_for.

Any other ideas to correct this code is more than welcomed, regarding it serves the same purpose :P.

Thanks Alot in advance,
Ahmed Ossama


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Mar 30, 2007 8:31 am
by Begby
What do you mean by changement? Perhaps you should write this out a bit better and post what some examples from the database, for instance the value of seeded_for and then what the value should be changed to after you are done.

Posted: Fri Mar 30, 2007 10:41 am
by RobertGonzalez
What is not working in that code you posted?

Posted: Fri Mar 30, 2007 11:25 am
by chasingSol
Thanks For The Replys, I changed the code its fine now

I added a row in the database which gets the value of the previous query, so when the new query is executed the previous value is grabbed from this row, and calculations are made upon it.
What is not working in that code you posted?
It was working fine, but the results are very strange.

Thanks