[Mysql] Get the fields of a query and put them on a variable
#8

I tried a new way, for example to select two fields:
pawn Код:
new str[350];
new query[300];
new nome[100];
new banned[100];
format(query, sizeof(query), "SELECT `username`,`banned` FROM `users` WHERE `username`='%s'", GetName(playerid));
mysql_query(query);
mysql_store_result();
if(mysql_fetch_row_format(str))
{
    sscanf(str, "p|ss", nome, banned);
    SendClientMessage(playerid, COLOR_GREEN, nome);
    SendClientMessage(playerid, COLOR_GREEN, banned);
}
mysql_free_result();
I used sscanf because the string I got from mysql_fetch_row_format is formatted like this:
Код:
field1|field2|...|fieldN
With the sscanf I get the individual fields so I put them on a variable and I can use them.
If I have multiple rows I think I have just to use the mysql_retrieve_row to move the pointer to the next row.

My problem wasn't the lack of the string escape, because I usually format the query in the same way and this was the first time I had a problem with it.
I don't want to use the mysql_get_field anymore lol, because this new way seems to work as I want. I hope my solution can help someone!
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)