UPDATING VALUES ON A MYSQL TABLE FIELD

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
intercampus
Forum Newbie
Posts: 2
Joined: Fri Aug 13, 2004 10:10 pm

UPDATING VALUES ON A MYSQL TABLE FIELD

Post by intercampus »

What is the command to use in case i would like to change the value of one field on a mysql table by number on descending order, i mean, i have a field call "number" on the table called "data" how can i set the value of "number" to:
0
1
2
3
4
each time the script is executed

thanx
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Are you talking about auto_generate in Number field ? But the example that you've given is not in descending order.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

* auto_increment ;)
User avatar
arcanechaos
Forum Newbie
Posts: 4
Joined: Sat Aug 14, 2004 3:27 am
Location: Long Beach, CA

Post by arcanechaos »

CREATE TABLE whatever (
whatever INT NOT NULL AUTO_INCREMENT,
etc..
etc..
PRIMARY KEY(something));
User avatar
arcanechaos
Forum Newbie
Posts: 4
Joined: Sat Aug 14, 2004 3:27 am
Location: Long Beach, CA

Post by arcanechaos »

oh, and the mysql select looks like this:

Code: Select all

mysql_query("SELECT * FROM whatever ORDER BY whatever DESC");
// or ASCE for ascending
intercampus
Forum Newbie
Posts: 2
Joined: Fri Aug 13, 2004 10:10 pm

hi

Post by intercampus »

the thing is that every time i add a data to the table it's put at the bottom that i fixed it sorting the table by date putting the latest data adition in the top of the table, what i need to do is to put number "0" to that data in one field and then changing the previous one to 1 the next to 2 etc being the case that before it was added that last data the now number 1 was 0, numer 2 was 1 etc.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

why make mysql do all that work, when you can just ask it to sort it with "ORDER BY" a lot easier?
Post Reply