display all records from a database table in gui -
Lolcio12 - 01.11.2012
Hi, I would like to do something like that after entering the command displays a list of the gui and prints all records in the table, and when you click a result of a specific action is performed.
OnPlayerCommandText:
Код:
if(!strcmp(cmdtext,"/cmd",true))
{
item[playerid] = 0;
mysql_query("SELECT item FROM table");
mysql_store_result();
while(mysql_retrieve_row())
{
mysql_fetch_field_row(resultstr,"item");
result=strval(resultstr);
format(str,sizeof(str),"id: %d\n",result);
strcat(guistr,str);
item[playerid]++;
}
mysql_free_result();
ShowPlayerDialog(playerid,666,DIALOG_STYLE_LIST,"items",guistr,"ok","");
return 1;
}
OnDialogResponse:
Код:
if(dialogid == 666)
{
if(listitem == item[playerid])
{
printf("clicked id: %d",item[playerid]);
}
return 1;
}
This unfortunately does not work and I have no idea how it could have been done differently. Please help me.
Re: display all records from a database table in gui -
Niko_boy - 01.11.2012
item[playerid]++ instead of that make it
item[playerid][SOMECOUNT] = result;
if you are able to see dialog already
and in dialogresponse
{
printf("no:%d",item[playerid][listitem] );
}
Re: display all records from a database table in gui -
AndreT - 01.11.2012
Here's something that may or may not be considered a protip: OnDialogResponse in DIALOG_STYLE_LIST case also packs the inputtext array so for example if you select "ID: 12" from the list dialog, the inputtext array will be "ID: 12" in your callback.
This eliminates the need for any sort of extra arrays to keep the row order in mind so the listitem can later be compared. But what you need to do is use sscanf to parse the "12" as an integer from the "ID: 12" string.
Or wait, actually, if you have a string like this:
"ID: 12"
you always know the number begins on index 6, so you can, I assume:
pawn Код:
new ID = strval(string[6]);
Give it a try!
Re: display all records from a database table in gui -
Lolcio12 - 01.11.2012
So this should be done in this way? :
Код:
new item[MAX_PLAYERS][99], SOMECOUNT;
OnPlayerCommandText:
Код:
if(!strcmp(cmdtext,"/cmd",true))
{
item[playerid] = 0;
mysql_query("SELECT item FROM table");
mysql_store_result();
while(mysql_retrieve_row())
{
mysql_fetch_field_row(resultstr,"item");
result=strval(resultstr);
format(str,sizeof(str),"id: %d\n",result);
strcat(guistr,str);
SOMECOUNT++;
item[playerid][SOMECOUNT]=result;
}
mysql_free_result();
ShowPlayerDialog(playerid,666,DIALOG_STYLE_LIST,"items",guistr,"ok","");
return 1;
}
OnDialogResponse:
Код:
if(dialogid == 666)
{
printf("clicked id: %d",item[playerid][listitem]);
return 1;
}
Re: display all records from a database table in gui -
AndreT - 01.11.2012
That's perhaps a bit faster than my solution (perhaps, maybe, maybe not), but wastes a lot more space. Space that does not necessarily need wasting
Re: display all records from a database table in gui -
iJumbo - 01.11.2012
https://sampforum.blast.hk/showthread.php?tid=190068 check this out
Re: display all records from a database table in gui -
Lolcio12 - 01.11.2012
Quote:
Originally Posted by AndreT
That's perhaps a bit faster than my solution (perhaps, maybe, maybe not), but wastes a lot more space. Space that does not necessarily need wasting ![Wink](images/smilies/wink.png)
|
Could you describe more your solution and apply it in the code? Because I do not fully understand them. Please.
Re: display all records from a database table in gui -
Lolcio12 - 02.11.2012
Quote:
Originally Posted by [ISS]jumbo
|
Download does not work.
Please help, how can you do it in a different way?
Re: display all records from a database table in gui -
Niko_boy - 02.11.2012
Quote:
Originally Posted by Lolcio12
So this should be done in this way? :
Код:
new item[MAX_PLAYERS][99], SOMECOUNT;
OnPlayerCommandText:
Код:
if(!strcmp(cmdtext,"/cmd",true))
{
item[playerid] = 0;
mysql_query("SELECT item FROM table");
mysql_store_result();
while(mysql_retrieve_row())
{
mysql_fetch_field_row(resultstr,"item");
result=strval(resultstr);
format(str,sizeof(str),"id: %d\n",result);
strcat(guistr,str);
SOMECOUNT++;
item[playerid][SOMECOUNT]=result;
}
mysql_free_result();
ShowPlayerDialog(playerid,666,DIALOG_STYLE_LIST,"items",guistr,"ok","");
return 1;
}
OnDialogResponse:
Код:
if(dialogid == 666)
{
printf("clicked id: %d",item[playerid][listitem]);
return 1;
}
|
this is realy gonna work cuz i also work on such things in similar ways , also i dont know exactly about the sequcne of dialog list atm
but
Quote:
That's perhaps a bit faster than my solution (perhaps, maybe, maybe not), but wastes a lot more space. Space that does not necessarily need wasting
|
Re: display all records from a database table in gui -
Lolcio12 - 02.11.2012
Ok, let's say I did it this way
Quote:
Originally Posted by Lolcio12
Код:
new item[MAX_PLAYERS][99], SOMECOUNT;
OnPlayerCommandText:
Код:
if(!strcmp(cmdtext,"/cmd",true))
{
item[playerid] = 0;
mysql_query("SELECT item FROM table");
mysql_store_result();
while(mysql_retrieve_row())
{
mysql_fetch_field_row(resultstr,"item");
result=strval(resultstr);
format(str,sizeof(str),"id: %d\n",result);
strcat(guistr,str);
SOMECOUNT++;
item[playerid][SOMECOUNT]=result;
}
mysql_free_result();
ShowPlayerDialog(playerid,666,DIALOG_STYLE_LIST,"items",guistr,"ok","");
return 1;
}
OnDialogResponse:
Код:
if(dialogid == 666)
{
printf("clicked id: %d",item[playerid][listitem]);
return 1;
}
|
How do I make an array Item does not have a limit (99),
In the tables for players, or vehicles can be used MAX_PLAYERS, MAX_VEHICLES, and what to do in this case?
My system will allow for dynamic addition, the limit would be records in a table from the database.