SqlLite question
#1

Hello i am creating a command which deletes a players pincode.
The command works like this:

PHP код:
if(!IsPlayerAdmin(playerid)) return ShowPlayerDialog(playerid, DIALOG_NONE, DIALOG_STYLE_MSGBOX, "Oops...", "You are not authorized to use this command", "OK", "");
    if(
strlen(params) <2) return SendClientMessage(playerid, -1, "USAGE: /deletepincode [PlayerName]");
    new 
DBResult:CLEAR_RESULT;
    new 
szQuery[128];
    
format(szQuery, sizeof(szQuery), "delete from `PINCODES` where `PlayerName` = '%s'", DB_Escape(params));
    
CLEAR_RESULT = db_query(PIN_DATABASE, szQuery);
    
db_free_result(CLEAR_RESULT); 
My question is, how do i check if the player table exists? so i can return a message like this player does not exist.
Reply
#2

you have to use db_num_rows like this:

PHP код:
    new DBResult:CLEAR_RESULT;
    new 
szQuery[128]; 
    
format(szQuery, sizeof(szQuery), "SELECT * from `PINCODES` where `PlayerName` = '%s'", DB_Escape(params)); 
    
CLEAR_RESULT = db_query(PIN_DATABASE, szQuery);
    if(
db_num_rows(CLEAR_RESULT))
    {
        
//it's found
    
}
    else
    {
        
//it's NOT found
    
} 
https://sampwiki.blast.hk/wiki/Db_num_rows
Reply
#3

Quote:
Originally Posted by Mugala
Посмотреть сообщение
you have to use db_num_rows like this:

PHP код:
    new DBResult:CLEAR_RESULT;
    new 
szQuery[128]; 
    
format(szQuery, sizeof(szQuery), "SELECT * from `PINCODES` where `PlayerName` = '%s'", DB_Escape(params)); 
    
CLEAR_RESULT = db_query(PIN_DATABASE, szQuery);
    if(
db_num_rows(CLEAR_RESULT))
    {
        
//it's found
    
}
    else
    {
        
//it's NOT found
    
} 
https://sampwiki.blast.hk/wiki/Db_num_rows
thanks
Reply
#4

yeah u're welcome
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)