PDA

View Full Version : Return query on the same function


BillieJoe
02/02/2015, 10:04 PM
I wanna do something like this

CMD:kick(playerid, params[])
{

new command[8] = "cmdkick";
new cmdlevel;

mysql_format(Mysql_users, query, sizeof(query), "SELECT * FROM `commands` WHERE `command` = '%s'", command);
mysql_tquery(Mysql_users, query, "", "");

printf("%s", query);
cmdlevel = cache_get_field_content_int(0, "adminlevel", Mysql_users);
printf("%s", cmdlevel);

if(PlayerData[playerid][AdminLevel] < cmdlevel) return SendUnathorizedMessage(playerid);

But after mysql_tquery it doesn't store the value and cmdlevel var is not working... I don't know how to do this on the same function. I don't want to create another function for this. Rep + for helping me to solve my problem :p

denNorske
02/02/2015, 10:24 PM
The easiest way would be to create a new function AFAIK. But:

CMD:kick(playerid, params[])
{

new command[8] = "cmdkick";
new cmdlevel;

mysql_format(Mysql_users, query, sizeof(query), "SELECT * FROM `commands` WHERE `command` = '%s'", command);

mysql_query(Mysql_users, query);
mysql_store_result();

new rows = mysql_num_rows(); //We get how many rows the query returned.
if(rows)
{
//it found something
printf("%s", query);
cmdlevel = cache_get_field_content_int(0, "adminlevel", Mysql_users);
printf("%s", cmdlevel);

if(PlayerData[playerid][AdminLevel] < cmdlevel) return SendUnathorizedMessage(playerid);
}





Im not 100% sure, but try using the mysql_query for this ?

BillieJoe
02/02/2015, 10:34 PM
Seems like mysql_store_result and mysql_num_rows doesn't exist on the BlueG's R39 include

BillieJoe
02/02/2015, 10:41 PM
Well, I don't know how but I did this way and worked

new command[8] = "cmdkick";
new cmdlevel;

mysql_format(Mysql_users, query, sizeof(query), "SELECT * FROM `commands` WHERE `command` = '%s'", command);

mysql_query(Mysql_users, query);

new rows = cache_num_rows();
if(rows) {
cmdlevel = cache_get_field_content_int(0, "adminlevel", Mysql_users);
}

Sime30
02/02/2015, 10:42 PM
The newest release is only for threaded scripts. That means you cannot use old functions like mysql_store_result and mysql_query

denNorske
03/02/2015, 12:25 AM
The newest release is only for threaded scripts. That means you cannot use old functions like mysql_store_result and mysql_query

Useful information.
Thanks for sharing

Abagail
03/02/2015, 12:35 AM
You shouldn't use outdated methods such as non-threaded scripts / plugins. R39 uses threading for a reason...