PDA

View Full Version : Setting ID's of vehicles - SQL


Derryd
09/10/2011, 09:20 AM
Does anyone know how I can make a command which re-orders the vehicle ID's in the database?

For example,

for(new i=0;i<203;i++)
{
format(sql, sizeof(sql), "UPDATE cars SET id = %d", i);
mysql_query(sql);
}

Thanks.

Derryd
09/10/2011, 09:35 AM
bump

AndreT
09/10/2011, 09:45 AM
That's a bad question to answer. I think it would be better to build up your table the way it doesn't have to be reordered.

Do you care to explain a little deeper about how your vehicles system works and how the table is set up? And why would it need reordering in the first place?

Edit: Ooh, you meant it that way. All you need is ORDER BY then.

Derryd
09/10/2011, 09:49 AM
It needs reordering because they are out of order..

Table:

id vehiclename model x y z angle

Vince
09/10/2011, 10:05 AM
SELECT * FROM cars ORDER BY id ASC

?

Derryd
10/10/2011, 06:21 AM
SELECT * FROM cars ORDER BY id ASC

?
:P

This reorders the results of a SQL statement, I need the physical fields reordered.

Haydz
10/10/2011, 06:31 AM
stock ResetVehicleID() {
mysql_query("ALTER TABLE `vehicles` DROP id");
mysql_query("ALTER TABLE `vehicles` ADD id INT(5) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
}


something like this?

Derryd
10/10/2011, 06:39 AM
stock ResetVehicleID() {
mysql_query("ALTER TABLE `vehicles` DROP id");
mysql_query("ALTER TABLE `vehicles` ADD id INT(5) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
}


something like this?
Nah this didn't do it. Hm..

There's 220 cars right, so I just want each id field for each car to go up from 1 - 220

EDIT: Wait it didn't even re-add the id field

Derryd
10/10/2011, 06:46 AM
Don't worry, Haydz, it worked. :D

Thanks.

Sry for double post.