CMD:v(playerid)
{
new string[128], count;
mysql_format(handle, string, sizeof(string), "SELECT * FROM `cars` WHERE `Owner` = '%s' ORDER BY `ID` DESC", GetName(playerid));
new Cache:result = mysql_query(handle, string);
format(string, sizeof(string), "ID\tModel\n");
for(new i = 1; i <= cache_num_rows(); i++)
{
format(string, sizeof string, "%s%d\t%s\n", string, i, CarInfo[i][CarOwner]);
count++;
}
if(count == 0) return SCM(playerid, -1, "You don't own any cars.");
cache_delete(result);
ShowPlayerDialog(playerid, DIALOG_CARS, DIALOG_STYLE_TABLIST_HEADERS, "Cars:", string, "Select", "Quit");
return 1;
}
cache_get_value_int(i, "ID", carid); format(string, sizeof(string), "%s%d\t%s\n", string, i, CarInfo[carid][CarOwner]);
|
PHP Code:
|
|
But now i have the problem that if i sellect car 2 it give's me someone else car from db, is like i am selecting car database id not the menu car id. |
for(new i = 1; i <= cache_num_rows(); i++)
for (new i, rows = cache_num_rows(); i < rows; i++) //Or, even better yet: new rows; cache_get_row_count(rows); for (new i; i < rows; i++)
|
What's the code under OnDialogResponse()?
Also: Code:
for(new i = 1; i <= cache_num_rows(); i++) Code:
for (new i, rows = cache_num_rows(); i < rows; i++) //Or, even better yet: new rows; cache_get_row_count(rows); for (new i; i < rows; i++) When you use cache_num_rows() in the statement part of the for() loop, it gets called every loop. When you assign it the way I did, cache_num_rows() is called once. Also: https://forum.sa-mp.com/showpost.php...4&postcount=12 Also also, I highly recommend you to use threaded queries. If your MySQL server would be lagging somehow, your entire server will freeze for everyone after using /v untill the results come in and are handled. |
case DIALOG_CARS:
{
new string[64], carid = listitem;
format(string, sizeof(string), "Selected: %d - PosX: %f", carid, CarInfo[carid][CarPosX]);
SCM(playerid, -1, string);
}
. You would either have to create some PVars to store the carid to the right listitem, or run the SQL code again to run the same code as in /v. If no data was altered, the listitem would be the same as the row number.
|
I thought so. listitem is not the same as the carid.
Let's say you have three results: * Infernus (carid 5)[listitem = 0] * Turismo (carid 9)[listitem = 1] * NRG (carid 12)[listitem = 2] I think that says enough . You would either have to create some PVars to store the carid to the right listitem, or run the SQL code again to run the same code as in /v. If no data was altered, the listitem would be the same as the row number. |
new count = 0; Selected[playerid][count] = carid; count++;
Selected[playerid][listitem]