Check records in mysql - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Check records in mysql (
/showthread.php?tid=650151)
Check records in mysql -
Oficer - 21.02.2018
Hello, how I can check the amount records from query?
In the table I have player nick and I want check is the player in the table.
PHP код:
mysql_format(Db, query, sizeof(query), "SELECT `players` from `table` WHERE `players`='Nick' ");
if(??? > 0)
{
...
}
else
{
...
}
Re: Check records in mysql -
Kaperstone - 21.02.2018
you use mysql_tquery to send the query and then on the callback you use cache_num_rows() to get the number of rows.
Example from Wiki
Код:
forward OnPlayerDataLoaded(playerid);
public OnPlayerConnect(playerid)
{
new query[128], pname[MAX_PLAYER_NAME];
new array[10] = {1, 2, ...};
GetPlayerName(playerid, pname, MAX_PLAYER_NAME);
mysql_format(MySQL, query, sizeof(query), "SELECT * FROM `players` WHERE `name` LIKE '%e'", pname);
mysql_tquery(MySQL, query, "OnPlayerDataLoaded", "dad", playerid, array, sizeof array);
return 1;
}
public OnPlayerDataLoaded(playerid, array[], array_size)
{
//Query processed, you can now execute cache functions (like cache_get_value_index) here.
printf("There are %d players with the same name.", cache_num_rows());
return 1;
}