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 i = 0
new Host[] = ""
new User[] = ""
new Pass[] = ""
new DB[] = ""
new Table[] = ""
new Handle:g_hSqlTuple;
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
set_task(1.0, "Mysql_Init")
}
public Mysql_Init()
{
g_hSqlTuple = SQL_MakeDbTuple(Host, User, Pass, DB)
new g_Error[512]
new ErrorCode
new Handle:SqlConnection = SQL_Connect(g_hSqlTuple, ErrorCode, g_Error, charsmax(g_Error))
if(SqlConnection == Empty_Handle)
set_fail_state(g_Error)
new Handle:Queries
Queries = SQL_PrepareQuery( SqlConnection,
"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(Queries, g_Error, charsmax(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(szTemp, charsmax(szTemp), "SELECT * FROM `%s`;", Table)
SQL_ThreadQuery(g_hSqlTuple, "Collect_Rgb", szTemp)
}
public Collect_Rgb(iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float: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(hQuery, 0, red, 3)
SQL_ReadResult(hQuery, 1, green, 3)
SQL_ReadResult(hQuery, 2, blue, 3)
format(rgb_colors[num_messages][0], 3, red)
format(rgb_colors[num_messages][1], 3, green)
format(rgb_colors[num_messages][2], 3, blue)
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(0, print_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
__________________