How to do this? (MySQL query) - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: How to do this? (MySQL query) (
/showthread.php?tid=206299)
How to do this? (MySQL query) -
hanzen - 03.01.2011
Okei, so maybe I'm just stupid or is making this command dynamic impossible?
I have the table `adminperks` in MySQL, where I can give a user a certain command. Table looks something like this:
Код:
playerid goto gethere flip delcar veh colorcar fixveh nos setskin gmx tp asv respawnallcars vehicle tod
Just a loads of commands, then I'm trying to make a /help command that lists all your available commands. The playerid is player[playerid][uid] btw.
So my question is: How can I do this? Is it even possible?
Would really appreciate some suggestions on this.
Re: How to do this? (MySQL query) -
JaTochNietDan - 03.01.2011
So basically you want a query to get the name of the columns in your table?
pawn Код:
SELECT column_name FROM information_schema.columns WHERE table_name = 'adminperks'
Then just store your information like any other MySQL query.
Re: How to do this? (MySQL query) -
hanzen - 03.01.2011
Quote:
Originally Posted by JaTochNietDan
So basically you want a query to get the name of the columns in your table?
pawn Код:
SELECT column_name FROM information_schema.columns WHERE table_name = 'adminperks'
Then just get your information like any other MySQL query.
|
Hehe yeah you made it sound so much easier. Then I want to print it in a string, how do I retrieve the data from the query?
Edit: The column is a enum and can either return 0 or 1, I only want to list the ones where it's set to 1.
Re: How to do this? (MySQL query) -
JaTochNietDan - 03.01.2011
Like any other query, it's the same thing.
pawn Код:
mysql_query("SELECT column_name FROM information_schema.columns WHERE table_name = 'adminperks'");
mysql_store_result();
new columns[10];
while(mysql_fetch_row(columns)) printf("Column name: %s",columns);
mysql_free_result();
Re: How to do this? (MySQL query) -
_rAped - 03.01.2011
Quote:
Originally Posted by JaTochNietDan
Like any other query, it's the same thing.
pawn Код:
mysql_query("SELECT column_name FROM information_schema.columns WHERE table_name = 'adminperks'"); mysql_store_result();
new columns[10];
while(mysql_fetch_row(columns)) printf("Column name: %s",columns);
mysql_free_result();
|
Yea but this will get all the fields independent of wether they are set to 1 or not.
_rAped -
hanzen - 03.01.2011
Quote:
Originally Posted by _rAped
Yea but this will get all the fields independent of wether they are set to 1 or not.
|
What he said.
Okei so I basicly made it work when printing to the server, but it won't print as a SendClientMessage()
pawn Код:
mysql_free_result();
mysql_query("SELECT column_name FROM information_schema.columns WHERE table_name = 'perks'"); mysql_store_result();
new commandstring[250], helpstring[256];
helpstring = "| Admin {ACACAC} ";
while(mysql_fetch_row(commandstring))
{
strins(helpstring, ", ", strlen(helpstring));
strins(helpstring, commandstring, strlen(helpstring));
}
SendClientMessage(playerid, COLOR_WHITE, helpstring);
printf(helpstring);
mysql_free_result();
Could it be the string being too small? How do I split it up in case? (Dynamicly split it up, so it will do it automaticly)