Little MYSQL question
#1

Hi everyone,

I was wondering, is it possible to load MYSQL without sscanf?
Or maybe with Sscanf, but then only temporary load them, or only directly display them.

Because I am making a command for the Police faction in my server, /trackperson, and with that they should be able to check a persons info, times arrested, number of crimes, e.t.c.

Anyone any idea about this?
Reply
#2

Hello there.

sscanf is used to seperate a string of text into multiple variables, mostly by finding spaces between each parameter.

If you load all of a player's data from the mysql database into variables when they connect, you can just display those variables (as long as they are updated when the player may change on of them).

If however you wish to retrieve the information for your /trackperson command with a mysql query, then the following will work:
(you will need to update the appropriate sections though)
pawn Код:
Inside the processing for the /trackperson command{
    ...
    new query[128],opname[24];
    GetPlayerName(otherplayerID,opname,sizeof(opname));
    mysql_format(connection, query,"SELECT `times arrested`, `number of crimes`,.... FROM `PlayersTable` WHERE `Username`='%s' LIMIT 0,1",opname);
    /*
    Connection = The connection to the mysql server (connection ID 1 by default)
    The query selects all the data you wish to display for the police officer, which is in the mysql table
    OtherplayerID=The ID of the player that the cop wishes to track
    */

    mysql_function_query(connection,query,true, "TrackQuery","i",playerid);
    //This'll run the query using a thread and caching
    //It will require the ID of the player who SENT the command, so the information can be sent to them
}

forward TrackQuery(playerid);
public TrackQuery(playerid){
    new rows,fields;
    cache_get_rows(rows,fields);
    if(!rows)SendClientMessage(playerid,0xFF0000FF,"No data was found on that player!";
    else {
        new timesArrested,num_of_crimes,temp[11];
        cache_get_field_content(0,"Times Arrested",temp),timesArrested=strval(temp);
        cache_get_field_content(0,"Number Of Crimes",temp),num_of_crimes=strval(temp);
        new str[128];
        format(str,128,"That player has committed %d crimes and has been arrested %d times",timesArrested,num_of_crimes);
        SendClientMessage(playerid,0xFFFFFFFF,str);
    }
    return 1;
}
That code is untested (mainly because I don't have the required tables or command.

You will need to modify it yourself, so hopefully if I have made any mistakes you will notice them.
Reply
#3

Thank you very much, I will look into this
Reply
#4

No problem. I am new to using mysql in SA:MP mysql.

(I assume you are using BlueG's plugin)
I found this useful topic on caching/threading queries:
https://sampforum.blast.hk/showthread.php?tid=337810

If you need additional information there is the wiki:
https://sampwiki.blast.hk/wiki/MySQL

and the original topic:
https://sampforum.blast.hk/showthread.php?tid=56564
Reply
#5

Quote:
Originally Posted by Hawky133
Посмотреть сообщение
No problem. I am new to using mysql in SA:MP mysql.

(I assume you are using BlueG's plugin)
I found this useful topic on caching/threading queries:
https://sampforum.blast.hk/showthread.php?tid=337810

If you need additional information there is the wiki:
https://sampwiki.blast.hk/wiki/MySQL

and the original topic:
https://sampforum.blast.hk/showthread.php?tid=56564
thanks a ton man, this is info i can really use
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)