MySQL Question
#1

Hi... this question might fail and be obviouse, however I just don't look through it -.-
I just downloaded gstyle's mysql plugin and now want it to replace my old database with a mysql one...
I'm a bit familar with php mysql and I guess that's why I don't look through...

I want to check whether a certain user is registered, without using all those subfunctions... (OnConnectResponse)

so if samp would be like php i'd do something like:
Код:
format(string, sizeof(string), "SELECT * FROM User WHERE name='%s'", name);
new result = mysql_query(string);
if(mysql_num_rows(result) != 1)
{
Register Dialog...
}
how would it work with samp ? -.-

EDIT: and how to get data later?.. like mysql_result(result, 0, "Score");
Reply
#2

Example of my code:
pawn Код:
format(str, sizeof(str), "SELECT * FROM `Users` WHERE `Name` = '%s'", pName(playerid));
    mysql_query(str);
    mysql_store_result();

    if(!mysql_num_rows())
    {
        ShowPlayerDialog(playerid, 0, DIALOG_STYLE_INPUT, "{0049FF}New Life Roleplay - {FFAF00}Register", "{FFAF00}Register by typing yo{0049FF}ur password in below.", "Register", "Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "{0049FF}New Life Roleplay - {FFAF00}Login", "{37DB45}Login by typing yo{0049FF}ur password in below.", "Login", "Quit");

    }
    mysql_free_result();
Reply
#3

k ty... and for my login dialog...
how would I e.g. get the "PlayerData[playerid][Level] = mysql_result(result, 0, 'Level');"? (read the level from the table)
Reply
#4

1. Store the data you retrieved. mysql_store_result().
2. Check if the player is registered by doing if(mysql_num_rows() > 0)
3. Retrieve data from the database, mysql_fetch_field("field", variable);

Example for score:
pawn Код:
new
      temp[32]
;

mysql_fetch_field("score", temp); PlayerData[playerid][Level] = strval(temp);
Reply
#5

If your asking about login loading stats, use sscanf.
Reply
#6

pawn Код:
new tmp[100];//ued for other things, too, therefore 100
mysql_fetch_field("Level", tmp);   //<-- error here
PlayerData[playerid][Level] = strval(tmp);
(2762) : error 035: argument type mismatch (argument 1)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)