AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Reading flags from MYSQL database (https://forums.alliedmods.net/showthread.php?t=246407)

devWaleed 08-17-2014 06:51

Reading flags from MYSQL database
 
PHP Code:

public SELECT_Handler(FailStateHandle:QueryError[], ErrcodeData[], DataSize){
    
    if(
FailState == TQUERY_CONNECT_FAILED){
        return 
set_fail_state("Couldn't connect to DB");        
    }else if(
FailState == TQUERY_QUERY_FAILED){
        return 
set_fail_state("Query failed");
    }    
    
    
//num     =    SQL_NumResults(Query);    
    
if(SQL_NumResults(Query) == 1){
        
num SQL_ReadResult(Query2);
                
client_print(0print_chat"Flag is %s"num);
    }
    return 
PLUGIN_CONTINUE;


Problem here is it is not printing what flags I have in MYSQL database.

On line 12: It prints "Flag is " and doesn't prints flags.

Database structure:
http://i.minus.com/ibpeuIuxaT1jGf.png

SpeeDeeR 08-17-2014 07:55

Re: Reading flags from MYSQL database
 
PHP Code:

/**
 * Retrieves the current result.
 * A successful query starts at the first result,
 *  so you should not call SQL_NextRow() first.
 * Passing no extra params - return int
 * Passing one extra param - return float in 1st extra arg
 * Passing two extra params - return string in 1st arg, max length in 2nd
 * Example:
 *  new num = SQL_ReadResult(query, 0)
 *  new Float:num2
 *  new str[32]
 *  SQL_ReadResult(query, 1, num2)
 *  SQL_ReadResult(query, 2, str, 31)
 */
native SQL_ReadResult(Handle:querycolumn, {Float,_}:...); 

Your flags must be a string.

aron9forever 08-17-2014 20:52

Re: Reading flags from MYSQL database
 
Quote:

Originally Posted by devWaleed (Post 2185104)
PHP Code:

public SELECT_Handler(FailStateHandle:QueryError[], ErrcodeData[], DataSize){
    
    if(
FailState == TQUERY_CONNECT_FAILED){
        return 
set_fail_state("Couldn't connect to DB");        
    }else if(
FailState == TQUERY_QUERY_FAILED){
        return 
set_fail_state("Query failed");
    }    
    
    
//num     =    SQL_NumResults(Query);    
    
if(SQL_NumResults(Query) == 1){
        
num SQL_ReadResult(Query2);
                
client_print(0print_chat"Flag is %s"num);
    }
    return 
PLUGIN_CONTINUE;


Problem here is it is not printing what flags I have in MYSQL database.

On line 12: It prints "Flag is " and doesn't prints flags.

Database structure:
http://i.minus.com/ibpeuIuxaT1jGf.png

there's so many things wrong with this
you're trying to print an int by the %String operator
this will only work if there's only one single row that applies to the query

if you want to save the flags as a string, make it SQL_ReadResult(Query, 2, szString, [len]);


All times are GMT -4. The time now is 12:57.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.