help with basic mysql
#1

Hi
I want to do a function to get ONLY ONE data from a row here it is

SELECT job FROM 'players' WHERE userid = %d
(job or whatever data)

how to put that in the script ? I'm still beginner
Reply
#2

i want help !
Reply
#3

Which MySQL Version do you use?
Reply
#4

R38 by BlueG
Reply
#5

Then do sth like this:

Код:
new string[128];
format(string,128,"SELECT job FROM `players` WHERE `userid` = '%d'",hereID);
mysql_function_query(dbHandle,string, true, "GetData", "i", playerid);

forward GetData(playerid);
public GetData(playerid)
{
    if(!cache_num_rows()) return SendClientMessage(playerid,-1,"Es wurde nichts gefunden!");
    new tmp[11];
    cache_get_row(0, 0, tmp);
    pInfo[playerid][job] = strval(tmp);
    return 1;
}
Reply
#6

If you want to keep your logic coupled, I recommend using y_inline from YSI:
pawn Код:
#include <YSI\y_va>
#include <YSI\y_inline>
#include <a_mysql>

//(...)

public OnPlayerConnect(playerid)
{
    new
        query[64]
    ;
    mysql_format(dbHandle, sizeof(query), "SELECT job FROM `players` WHERE `userid` = %d", hereID);

    inline YourHandle() {
        new
            rows = cache_get_row_count(dbHandle)
        ;
        //Playerid is still available here!
        if (!rows) {
            va_SendClientMessage(playerid, 0xBADA55AA, "Sorry, there is not a single job for player %d", hereID);
            return;
        }

        new
            jobID
        ;
        for (new row = 0; row != rows; ++i) {
            jobID = cache_get_field_content_int(0, "job", dbHandle);
       
            printf("Fetched job %d", jobID);
        }
    }

    mysql_tquery_inline(dbHandle, query, using inline Yourhandle, "");

    //Watch out, outside that inline you can't be sure that the query was already finished
}
Reply
#7

I want to do something like that

stock GetPlayerNameByID(playerid)

This function will return the player name by his ID (incremented)

SELECT username FROM player WHERE id = %d

And then I can format message with
format(string, sizeof(string), "%s is (not) connected !", GetPlayerNameByID(playerid));
(and many other stuff like this)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)