How to do this? (MySQL query)
#1

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

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

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

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

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

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)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)