Mysql creating tables
#8

If you're already using threaded queries (which is the only type R7 supports) I recommend updating to R15 as it adds a couple of extra features and fixed some bugs.

/rant

Now ontopic: You're using mysql_num_rows inside OnPlayerConnect. mysql_num_rows retrieves the number of rows from a result set after sending a SELECT or SHOW query. You'll need to send a SELECT query to check for the player in the table, then in the callback (which you specify) you can use cache_get_data to retrieve the data and check for rows.

https://sampforum.blast.hk/showthread.php?tid=390428 Here's an example gamemode using this method. I recommend reading it - it helped me a lot!

Summary:

Send a SELECT query in OnPlayerConnect:

pawn Код:
new
    szQuery[ 90 ]
;
format( szQuery, sizeof( szQuery ), "SELECT * from `your_table_here` WHERE `name` = '%s' LIMIT 1", Name( playerid ));
mysql_function_query( handle, szQuery, true, "OnUserCheck", "i", playerid );
Check rows in the specified callback (OnUserCheck):

pawn Код:
forward OnUserCheck(playerid);
public OnUserCheck(playerid)
{
    new
        rows,
        fields
    ;
    cache_get_data( rows, fields, handle );
    if( rows )
    {
        // exists - player should log in
    }
    else
    {
        // doesn't exist - player should register
    }
    return true;
}
And that's about it. Keep in mind that this is just a very very rough example.

You should read this tutorial: https://sampforum.blast.hk/showthread.php?tid=337810 on using cache in R7 and newer
Reply


Messages In This Thread
Mysql creating tables - by MadafakaPro - 21.03.2013, 19:43
Re: Mysql creating tables - by Jstylezzz - 21.03.2013, 19:49
Re: Mysql creating tables - by MadafakaPro - 21.03.2013, 19:51
Re: Mysql creating tables - by LarzI - 21.03.2013, 19:51
Re: Mysql creating tables - by MadafakaPro - 21.03.2013, 20:09
Re: Mysql creating tables - by LarzI - 21.03.2013, 20:11
Re: Mysql creating tables - by MadafakaPro - 21.03.2013, 20:12
Re: Mysql creating tables - by LarzI - 21.03.2013, 20:21
Re: Mysql creating tables - by Scenario - 21.03.2013, 20:31
Re: Mysql creating tables - by MadafakaPro - 21.03.2013, 20:36

Forum Jump:


Users browsing this thread: 3 Guest(s)