SA-MP Forums Archive
Take information from mysql - 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: Take information from mysql (/showthread.php?tid=182712)



Take information from mysql - vection - 12.10.2010

I need to take somthing from MYSQL, for example, i need take a field which calls "keycar" and i need only this.
how i can take it ? somthing like this: SELECT blablabla WHERE user = %s
and i need to put it on other field.


Re: Take information from mysql - Miguel - 13.10.2010

Example:
pawn Code:
public OnPlayerConnect(playerid)
{
    new
        value,
        name[24],
        query[79],
        field[12];
       
    GetPlayerName(playerid, name, sizeof(name)); // we need the name of the player to make the query
    format(query, sizeof(query), "SELECT keycar FROM players WHERE Nickname = '%s' LIMIT 1", name); // we format "query"
    // it means it will look for the content of "keycar" in the table "players" where the nickname is the name of the player,
    // LIMIT 1 means it will only take the first value
    mysql_query(query); // we make the query with "query" ("SELECT keycar FROM blablabla")
    mysql_store_result(); // we store the result of the query
    if(mysql_num_rows() > 0) // if theres any value then:
    {
        mysql_fetch_row_format(field); // fetch the value to the string "field"
        value = strval(field); // convert the string to an integer
    }
    mysql_free_result(); // free the mysql memory
    return 1;
}