MySQL Adding +1
#1

Hi sorry if this has been asked before but cant find anything and searching plus one or +1 wont work in the forums search results.

Im trying to make it so i can see how many times a player has been kicked from the server
Im currently converting from ini to mysql and its going well but im stuck with adding +1 on a number in a row.

So like
If times kicked is 1 then this script adds a +1 to that making it 2

This is what iv done so far.

pawn Код:
stock ServerKick2(playerid, reason[])
{
    new string[158];
    new handle = SQL::OpenEx(SQL::READ, ""PLAYERS_TABLE"", "username", GetName(playerid));
    SQL::WriteString(handle, "LastKickReason", reason);
    SQL::WriteInt(handle, "TimesKicked", +1);
    SQL::Close(handle);
    Kick(playerid);
This was my old dini code that i used and am going off

pawn Код:
if(dini_Exists(file))
    {
        dini_Set(file, "LastKickReason", reason);
        dini_IntSet(file, "TimesKicked", (dini_Int(file, "TimesKicked") + 1));
    }
Sorry if i explaned this a bit weird. Thanks in advance.

Edit: Sorry just relised this is proberbly in the wrong section. sorry about that.
Reply
#2

You'll have to execute the query manually:
PHP код:
"UPDATE "PLAYERS_TABLE" SET TimesKicked=TimesKicked+1 WHERE username='%e' LIMIT 1"GetName(playerid
Reply
#3

Im sorry iv only just started learning all this mysql malarkey :P
Im using ThePhenix's easy mysql include to help (https://sampforum.blast.hk/showthread.php?tid=590310)

How would i do this in that includes way.

Looking at the natives iv been looking at this and am guessing it does what your trying to tell me to do
"native SQL::SetIntEntry(const table[], const field[], value, const column[], columnID, connectionHandle = 1);"

Just wondering how i would put what your tell me to do in the includes way
is it something like this?

pawn Код:
SQL::SetIntEntry(""PLAYERS_TABLE"", "TimesKicked", "1", "username", columnID, connectionHandle = 1);
Sorry if its a bother. Been putting mysql off for the past year but really need to crack on with it now as getting some very noticeable lag with ini lol Just annoying that one little thing is stopping me

Thanks for your help.
Reply
#4

All those "easy" database includes (meanwhile adding complicated syntax) just transform an SQL database into a glorified file system, without harnessing the true potential of SQL. There's hardly any support for grouping or ordering, let alone joining other tables. If you're going to use one of those systems you might as well just stick to files.

Do what Konstantinos said because those functions (not really natives) aren't going to cut it.
Reply
#5

At the end of the day Vince, a gloridied file system is all i need. Im not a expert at mysql and proberbly never will be. I personly dont have the time in my life to sit down and learn it or even attempt to start scripting with it. I run a server that gets about 40 - 50 players at peak time and with all the saving and loading with all the files and file buildup in the folders, it causes a big of lag. All i need is a simple mysql database where i can access the files quicker ie phpmyadmin and create backups quicker. And as everyone says mysql is quicker and lags less or even not at all than ini. Then the "easy" database includes suit me down the ground.

Im not doing any fancy business of ucp's or anything like that. Just need things to load & save etc..

So thats why im using it and thats why im asking for just a little help with a problem i am having.
I hardly if ever ask for help on this forum but with this i was stuck and was hoping someone would help. Konstantinos did help but he of course put it in the real mysql language of which i dont understand. This is why i made my second post.

So if anyone does know how to help with that. Would be very much appricated
Reply
#6

It is actually easier to update it without the use of that include. Your players table should have auto increment enabled and store the player's unique ID somewhere (to global player-array). It is then quite faster to update a row or select data using this ID in WHERE clause. I don't want to confuse you more so I'll just use the example from my post above:
pawn Код:
new Query[100];
mysql_format(connection_handle, Query, sizeof Query, "UPDATE "PLAYERS_TABLE" SET TimesKicked=TimesKicked+1 WHERE username='%e' LIMIT 1", GetName(playerid));
mysql_tquery(connection_handle, Query, "", "");
If you wanted to do the above by using that include, you would have to use SQL::Open with type of SQL::READ, store the column's value, use SQL::Close and now open a new one to write to the column with value of the stored variable + 1 and then again close it.

It seems way more complicated, doesn't it? Keep everything else as it is (using the include's functions) but update that specific column with the way I showed you.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)