Check records in mysql
#1

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(Dbquerysizeof(query), "SELECT `players` from `table` WHERE `players`='Nick' ");
    
    if(??? > 
0)
        {
            ...
        }
        else
        {
            ...
        } 
Reply
#2

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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)