SA-MP Forums Archive
MySQL Order By help - 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: MySQL Order By help (/showthread.php?tid=423946)



MySQL Order By help - PaulDinam - 20.03.2013

How can I show it by order, `slot` ?

pawn Код:
stock ShowPlayerVehicleList(playerid)
{
    new query[500];
    format(query, sizeof(query), "SELECT * FROM `ownedvehicles` WHERE `owner` = '%s'", GetName(playerid));
    mysql_function_query(dbHandle, query, true, "OnVehicleListDisplay", "i", playerid);
}
Something like that?
ORDER BY

because it shows the opposite always, like starting from 3, then to 2 and 1.

I want it to read from 1, 2, 3



Re: MySQL Order By help - Toni - 20.03.2013

I'm a little rusty to this, haven't done it in a while but if you were going to use ORDER BY I'm pretty certain you don't need the WHERE statement as well...you're already getting something in return in a certain way.

pawn Код:
stock ShowPlayerVehicleList(playerid)
{
    new query[500];
    format(query, sizeof(query), "SELECT * FROM ownedvehicles ORDER BY slot [DESC]");
    mysql_function_query(dbHandle, query, true, "OnVehicleListDisplay", "i", playerid);
}
I left [DESC] (obviously remove the brackets if you were going to use it though) in there if you wanted to order them by descending order, if not it's defaulted to ascending.


Re: MySQL Order By help - PaulDinam - 20.03.2013

Well, I need WHERE `owner` because if not it will show me all other player vehicles.
But thanks for the format, I did this and it works great.

pawn Код:
format(query, sizeof(query), "SELECT * FROM `ownedvehicles` WHERE `owner` = '%s' ORDER BY `slot` LIMIT 3", GetName(playerid));



Re: MySQL Order By help - Toni - 20.03.2013

I'm glad it worked out just a tip, you don't have to add `` around every field. It's just extra typing!