MySQL Question - 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: MySQL Question (
/showthread.php?tid=211775)
MySQL Question -
Sascha - 15.01.2011
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");
Re: MySQL Question -
Anthonyx3' - 15.01.2011
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();
Re: MySQL Question -
Sascha - 15.01.2011
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)
Re: MySQL Question -
hanzen - 15.01.2011
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);
Re: MySQL Question -
Anthonyx3' - 15.01.2011
If your asking about login loading stats, use sscanf.
Re: MySQL Question -
Sascha - 16.01.2011
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)