MySQL Order By help
#1

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
Reply
#2

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.
Reply
#3

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));
Reply
#4

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


Forum Jump:


Users browsing this thread: 1 Guest(s)