Raised This Month: $51 Target: $400
 12% 

MYSQL Read Numbers and save.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
oxygen935
Veteran Member
Join Date: Jun 2012
Location: Athens, Greece
Old 02-27-2014 , 07:09   MYSQL Read Numbers and save.
Reply With Quote #1

Hey alliedmodders!

I have a little problem on reading some numbers from mysql.
I saved some RGB Colors on mysql and now i wanna read them. But when i put "0" "255" "255", where 0=red, 255=green, 255=blue, it shows on chat: R: 02255, G: 2255, B: 255! instead of show: R: 0, G: 255, B: 255

Here is the code, can u help me?
PHP Code:
#include <amxmodx>
#include <sqlx>

#define PLUGIN "Mysql RGB"
#define VERSION "1.0"
#define AUTHOR "oxygen"

new rgb_colors[20][3]
new 
num_messages
new bool:msg_exists
new 0

new Host[]        = ""
new User[]        = ""
new Pass[]        = ""
new DB[]           = ""
new Table[]     = ""

new Handle:g_hSqlTuple;

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
set_task(1.0"Mysql_Init")
}

public 
Mysql_Init()
{
    
g_hSqlTuple SQL_MakeDbTuple(HostUserPassDB)
    
    new 
g_Error[512]
    new 
ErrorCode
    
new Handle:SqlConnection SQL_Connect(g_hSqlTupleErrorCodeg_Errorcharsmax(g_Error))
    
    if(
SqlConnection == Empty_Handle)
        
set_fail_state(g_Error)
    
    new 
Handle:Queries
    Queries 
SQL_PrepareQuerySqlConnection
    
"CREATE TABLE IF NOT EXISTS `%s`\
    (`red` VARCHAR(4) NOT NULL,\
    `green` VARCHAR(4) NOT NULL,\
    `blue` VARCHAR(4) NOT NULL)"
,
    
Table)
    
    if(!
SQL_Execute(Queries))
    {
        
SQL_QueryError(Queriesg_Errorcharsmax(g_Error))
        
set_fail_state(g_Error)
    }
    
    
SQL_FreeHandle(Queries)    
    
SQL_FreeHandle(SqlConnection)
    
    
set_task(1.0"Load_Table")
}

public 
Load_Table()
{
    new 
szTemp[512
    
formatex(szTempcharsmax(szTemp), "SELECT * FROM `%s`;"Table)
    
SQL_ThreadQuery(g_hSqlTuple"Collect_Rgb"szTemp)
}

public 
Collect_Rgb(iFailStateHandle:hQueryszError[ ], iErroriData[ ], iDataSizeFloat:fQueueTime)
{
    if(
iFailState == TQUERY_CONNECT_FAILED
    
|| iFailState == TQUERY_QUERY_FAILED)
    {
        
log_amx"Query failed on collect RGB Colors." )
    } 
    else if( 
SQL_NumResults(hQuery))
    {
        new 
red[4], green[4], blue[4]
        
        
num_messages 0
            
        
while(SQL_MoreResults(hQuery)) 
        {
            
SQL_ReadResult(hQuery0red3)
            
SQL_ReadResult(hQuery1green3)
            
SQL_ReadResult(hQuery2blue3)
            
format(rgb_colors[num_messages][0], 3red)
            
format(rgb_colors[num_messages][1], 3green)
            
format(rgb_colors[num_messages][2], 3blue)
            
num_messages++
            
            
SQL_NextRow(hQuery)
        }
        
set_task(4.0"advertise")
        if(
num_messages 0)
        {
            
msg_exists true
        
}
        else
        {
            
log_amx("No RGB colors LOADED!")
        }
    }
}

public 
advertise()
{
    if(
msg_exists)
    {
        
client_print(0print_chat"R: %s, G: %s, B: %s"rgb_colors[i][0], rgb_colors[i][1], rgb_colors[i][2])
        
i++
        if(
i>num_messages)
            
i=0
        set_task
(5.0"advertise")
    }

With Respect,
Oxygen
__________________
Quote:
Originally Posted by quark View Post
You're a genius
Stopped any pawn work cause of university for computer science

Last edited by oxygen935; 02-27-2014 at 07:10.
oxygen935 is offline
Send a message via Skype™ to oxygen935
minato
Senior Member
Join Date: May 2010
Location: Rosario
Old 03-02-2014 , 14:30   Re: MYSQL Read Numbers and save.
Reply With Quote #2

PHP Code:
#include <amxmodx>
#include <sqlx>

#define PLUGIN "Mysql RGB"
#define VERSION "1.0"
#define AUTHOR "oxygen"

new rgb_colors[20][3][4]
new 
num_messages
new bool:msg_exists
new 0;

new 
Host[]        = ""
new User[]        = ""
new Pass[]        = ""
new DB[]           = ""
new Table[]     = ""

new Handle:g_hSqlTuple;

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
set_task(1.0"Mysql_Init")
}

public 
Mysql_Init()
{
    
g_hSqlTuple SQL_MakeDbTuple(HostUserPassDB)
    
    new 
g_Error[512]
    new 
ErrorCode
    
new Handle:SqlConnection SQL_Connect(g_hSqlTupleErrorCodeg_Errorcharsmax(g_Error))
    
    if(
SqlConnection == Empty_Handle)
        
set_fail_state(g_Error)
    
    new 
Handle:Queries
    Queries 
SQL_PrepareQuerySqlConnection
    
"CREATE TABLE IF NOT EXISTS `%s`\
    (`red` VARCHAR(4) NOT NULL,\
    `green` VARCHAR(4) NOT NULL,\
    `blue` VARCHAR(4) NOT NULL)"
,
    
Table)
    
    if(!
SQL_Execute(Queries))
    {
        
SQL_QueryError(Queriesg_Errorcharsmax(g_Error))
        
set_fail_state(g_Error)
    }
    
    
SQL_FreeHandle(Queries)    
    
SQL_FreeHandle(SqlConnection)
    
    
set_task(1.0"Load_Table")
}

public 
Load_Table()
{
    new 
szTemp[512
    
formatex(szTempcharsmax(szTemp), "SELECT * FROM `%s`;"Table)
    
SQL_ThreadQuery(g_hSqlTuple"Collect_Rgb"szTemp)
}

public 
Collect_Rgb(iFailStateHandle:hQueryszError[ ], iErroriData[ ], iDataSizeFloat:fQueueTime)
{
    if(
iFailState == TQUERY_CONNECT_FAILED
    
|| iFailState == TQUERY_QUERY_FAILED)
    {
        
log_amx"Query failed on collect RGB Colors." )
    } 
    else if( 
SQL_NumResults(hQuery))
    {
        new 
red[4], green[4], blue[4]
        
        
num_messages 0
    
        
while(SQL_MoreResults(hQuery)) 
        {
            
SQL_ReadResult(hQuery0redsizeof red -1)
            
SQL_ReadResult(hQuery1greensizeof green -1)
            
SQL_ReadResult(hQuery2bluesizeof blue -1)
            
copy(rgb_colors[num_messages][0], 3red)
            
copy(rgb_colors[num_messages][1], 3green)
            
copy(rgb_colors[num_messages][2], 3blue)
            
            
num_messages++
            
            
SQL_NextRow(hQuery)
        }
        
        if(
num_messages 0)
        {
            
msg_exists true
            set_task
(4.0"advertise")
        }
        else
        {
            
log_amx"failed on collect RGB Colors." )
        }
    }
}

public 
advertise()
{
    if(
msg_exists)
    {
        if(
i>=num_messages)
            
i=0;
            
        
client_print(0print_chat"R: %s, G: %s, B: %s"rgb_colors[i][0], rgb_colors[i][1], rgb_colors[i][2])
        
i++
        
set_task(5.0"advertise")
    }

__________________
minato is offline
Send a message via MSN to minato
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:29.


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