Hello David, I have searched everywhere on the net and could not find a quick solution, so I decided to turn to your forum, since every advice you have gave me up to now worked like a charm with PT.
Here is the situation:
I have a database of products with an auto increment ID field, so if I "ORDER BY ID DESC" I have a list of latest products displayed.
The DB gets a few hundred new products daily, and some other few hundreds of them get "expired" deleted from DB (also daily)
Now here is what I need to do:
I need to take an existing product and update its ID to the latest. - In other words, - delete the product from DB and than insert it back (with exactly the same values in all fields except its ID) so that it would get the latest ID and would be the first on the list.
I am capable of writing it the way I have explained above, but wanted to ask you, perhaps there is an easier way to update just the ID instead of deleting the entire product from DB and than to inserting it back just because I want to update its ID...
Any thoughts are welcome and appreciated! (as usual)
Thanks
Paul


Hi Paul, Perhaps slightly
Hi Paul,
Perhaps slightly easier than deleting and fully re-creating the row would be to select MAX(id) from the table, and then do an UPDATE, for example:
$result = mysql_query("SELECT id FROM table WHERE name='Product To Update'");$row = mysql_fetch_assoc($result);
$old_id = $row["id"];
$result = mysql_query("SELECT MAX(id) AS max_id FROM table");
$row = mysql_fetch_assoc($result);
$new_id = $row["max_id"]+1;
mysql_query("UPDATE table SET id=".$new_id." WHERE id=".$old_id);
Hope this helps!
Cheers,
David.
Great! Thanks David, I did
Great! Thanks David, I did not know that the ID field can be updated that easily, I thought that the "auto-increment number" in the DB will not "auto-update" if I just UPDATE the ID, and that is why I wanted to DELETE the product and than to INSERT it back in the first place!
Works great, thanks again! - You are amazing!