mysql help needed +rep! - 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)
+--- Thread: mysql help needed +rep! (
/showthread.php?tid=314220)
mysql help needed +rep! -
PawnoQ - 29.01.2012
hi,
i have a code that shall show the player the score he has earned per game session.
This values are saved to a mysql database but the problem is it isnt saving the score of his current session but all his score he has in general.
I hope you can help me

No mysql log errors or warnings etc.
pawn Код:
new DOMScore[MAX_PLAYERS][2];
//OnPlayerConnect
DOMScore[playerid][0]=0;
//OnPlayerDisconnect
DOMScore[playerid][1]=(GetPlayerScore(playerid)-DOMScore[playerid][0]);
new query[128],query2[128],pname[24];
GetPlayerName(playerid,pname,24);
format(query, sizeof(query), "SELECT name FROM `DOM` WHERE name = '%s' LIMIT 1", pname);
mysql_query(query);
mysql_store_result();
new rows = mysql_num_rows();
if(!rows)
{
format(query2,sizeof(query2), "INSERT INTO `DOM` (name, score) VALUES('%s','%d')",pname,DOMScore[playerid][1]);
mysql_query(query2);
}
else if(rows == 1)
{
new queryDC[128],pDOMtmp;
format(queryDC, sizeof(queryDC), "SELECT score FROM `DOM` WHERE `name` = '%s'", pname);
mysql_query(queryDC);
mysql_store_result();
new rowD[24];
mysql_fetch_row(rowD);
sscanf(rowD, "p<|>d",pDOMtmp);
format(query2, sizeof(query2), "UPDATE pDOM SET score=%d WHERE name='%s'",(pDOMtmp+DOMScore[playerid][1]),pname);
mysql_query(query2);
}
mysql_free_result();
Re: mysql help needed +rep! -
Ricop522 - 29.01.2012
pawn Код:
new DOMScore[MAX_PLAYERS][2];
//OnPlayerConnect
DOMScore[playerid][0]=0;
//OnPlayerDisconnect
DOMScore[playerid][1]=(GetPlayerScore(playerid)-DOMScore[playerid][0]);
new query[128],query2[128],pname[24];
GetPlayerName(playerid,pname,24);
format(query, sizeof(query), "SELECT * FROM `DOM` WHERE name = '%s' LIMIT 1", pname);
mysql_query(query);
mysql_store_result();
new rows = mysql_num_rows();
if(!rows)
{
format(query2,sizeof(query2), "INSERT INTO `DOM` (name, score) VALUES('%s','%d')",pname,DOMScore[playerid][1]);
mysql_query(query2);
}
else
{
new queryDC[128],pDOMtmp;
format(queryDC, sizeof(queryDC), "SELECT score FROM `DOM` WHERE `name` = '%s'", pname);
mysql_query(queryDC);
mysql_store_result();
new str[128], score;
mysql_fetch_row_format(query,"|"))
mysql_fetch_field_row(str, "score");
score = (strval(str) + DOMScore[playerid][1]);
format(query2, sizeof(query2), "UPDATE DOM SET score=%d WHERE name='%s'",score,pname);
mysql_query(query2);
}
mysql_free_result();
Try =)