PDA

View Full Version : SQLite question


jbankss
03/12/2016, 08:54 PM
Hello. I was wondering if it's possible to select a specific row(?) :cool:

Say I have a dialog(list) with the top players and want to select a row based on OnDialogResponse with listitem?

Example:

if(dialogid == DIALOG_TOP)
{
if(response) {
format(Query,sizeof(Query), "SELECT * FROM `USERS` ORDER BY `KILLS` DESC LIMIT 25");
Result = db_query(Database, Query);
if(db_num_rows(Result))
{
db_select_row(listitem) // function im looking for..? :d
db_get_field_assoc(Result, "OwnerName", string, 48);
}
}



And another issue, the query below doesnt give me any results, any ideas as to why?
format(Query,sizeof(Query), "SELECT * FROM `VEHDATA` WHERE `OwnerID` = %i ORDER BY `VehID` DESC LIMIT 15", PlayerInfo[playerid][UserID]);


Thanks in advance!

BrianFaria
03/12/2016, 10:03 PM
I do not understand.

Yaa
03/12/2016, 10:06 PM
format(Query,sizeof(Query), "SELECT * FROM `VEHDATA` WHERE `OwnerID` = '%i' ORDER BY `VehID` DESC LIMIT 15", PlayerInfo[playerid][UserID]);

jbankss
04/12/2016, 02:20 AM
format(Query,sizeof(Query), "SELECT * FROM `VEHDATA` WHERE `OwnerID` = '%i' ORDER BY `VehID` DESC LIMIT 15", PlayerInfo[playerid][UserID]);

What you did was add apostrophes and thats for strings, not integers. (afaik)

I do not understand.

I'm looking for something that allows me to select a specific row from a query result, basically what "db_next_row" does but selects a specific row based on the "ORDER BY" order.

Another example:

(a list showing the top players in order)
https://i.gyazo.com/12255d3fbc90c3781dada5f3b9276254.png

In OnDialogResponse I want to perform a query that selects the correct row(based on the order by order) based off of what the user selected in the dialog.

I can see how this might sound confusing but I hope you understand(I might have to end up storing the values in variables, but I'd prefer not to)

Konstantinos
04/12/2016, 10:33 AM
It is not possible to select a row directly, you will have to use db_next_row function. If you know that the limit is 25, then an array with that size and assigning the data to this array is the only way I can think of so you can easily access the element with index equal to listitem.

Based on your last example, what you're trying to do is send another query with the player selected? You can easily do this by using inputtext (which holds the text of the specific item) and retrieve the name (in your case strfind to get the pos of " -"; that'll be the end of the player's name). Last, execute the query with the name in WHERE clause.

jbankss
04/12/2016, 12:11 PM
It is not possible to select a row directly, you will have to use db_next_row function. If you know that the limit is 25, then an array with that size and assigning the data to this array is the only way I can think of so you can easily access the element with index equal to listitem.

Based on your last example, what you're trying to do is send another query with the player selected? You can easily do this by using inputtext (which holds the text of the specific item) and retrieve the name (in your case strfind to get the pos of " -"; that'll be the end of the player's name). Last, execute the query with the name in WHERE clause.

Thank you very much. :cool: