help with basic mysql -
Veng3eur - 10.03.2015
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
Re: help with basic mysql -
Veng3eur - 11.03.2015
i want help !
AW: help with basic mysql -
Kaliber - 11.03.2015
Which MySQL Version do you use?
Re: help with basic mysql -
Veng3eur - 11.03.2015
R38 by BlueG
AW: help with basic mysql -
Kaliber - 11.03.2015
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;
}
Re: help with basic mysql -
Misiur - 11.03.2015
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
}
Re: help with basic mysql -
Veng3eur - 11.03.2015
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)