SA-MP Forums Archive
Setting ID's of vehicles - SQL - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Setting ID's of vehicles - SQL (/showthread.php?tid=288831)



Setting ID's of vehicles - SQL - Derryd - 09.10.2011

Does anyone know how I can make a command which re-orders the vehicle ID's in the database?

For example,

pawn Код:
for(new i=0;i<203;i++)
        {
         format(sql, sizeof(sql), "UPDATE cars SET id = %d", i);
             mysql_query(sql);
        }
Thanks.


Re: Setting ID's of vehicles - SQL - Derryd - 09.10.2011

bump


Re: Setting ID's of vehicles - SQL - AndreT - 09.10.2011

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.


Re: Setting ID's of vehicles - SQL - Derryd - 09.10.2011

It needs reordering because they are out of order..

Table:

id vehiclename model x y z angle


Re: Setting ID's of vehicles - SQL - Vince - 09.10.2011

Код:
SELECT * FROM cars ORDER BY id ASC
?


Re: Setting ID's of vehicles - SQL - Derryd - 10.10.2011

Quote:
Originally Posted by Vince
Посмотреть сообщение
Код:
SELECT * FROM cars ORDER BY id ASC
?
:P

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


Re: Setting ID's of vehicles - SQL - Haydz - 10.10.2011

pawn Код:
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?


Re: Setting ID's of vehicles - SQL - Derryd - 10.10.2011

Quote:
Originally Posted by Haydz
Посмотреть сообщение
pawn Код:
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


Re: Setting ID's of vehicles - SQL - Derryd - 10.10.2011

Don't worry, Haydz, it worked.

Thanks.

Sry for double post.