Raised This Month: $ Target: $400
 0% 

Mysql result ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
MiniBrackeur
Senior Member
Join Date: Oct 2010
Old 02-21-2013 , 13:26   Mysql result ?
Reply With Quote #1

Hello, I search how to get a array from a query mysql ?

PHP Code:
new Handle:db;
public 
sql_init()
{
    new 
sqlhostname[35], sqluser[35], sqlpass[35], sqldbname[35], errcodeerror[128];
    
get_cvar_string("amx_sql_host"sqlhostname34);
    
get_cvar_string("amx_sql_user"sqluser34);
    
get_cvar_string("amx_sql_pass"sqlpass34);
    
get_cvar_string("amx_sql_db"sqldbname34);
    new 
Handle:tuple SQL_MakeDbTuple(sqlhostnamesqlusersqlpasssqldbname);
    
db SQL_Connect(tupleerrcodeerrorcharsmax(error));
    return 
PLUGIN_CONTINUE;
}
public 
end_notemap()
{
    new 
players[32], playerscount;
    
get_players(playersplayerscount"ch");
    for(new 
iplayerscounti++)
    {
        new 
id players[i];
        
menu_cancel(id);
    }
    
    new 
Handle:query SQL_PrepareQuery(db"SELECT `verygood`, `good`, `bad`, `verybad`, `none` FROM `cs_notemap` WHERE `map`='%s'"g_mapname);
    new 
result[4];
    
/*
        
        How to get the four result in the arry result ?
        
    */
    
g_vote_verygood += result[0];
    
g_vote_good += result[1];
    
g_vote_bad += result[2];
    
g_vote_verybad += result[3];
    
g_vote_none += result[4];
    
    
query SQL_PrepareQuery(db"UPDATE `cs_notemap` SET `verygood`='%d', `good`='%d', `bad`='%d', `verybad`='%d', `none`='%d' WHERE `map`='%s'"g_vote_verygoodg_vote_goodg_vote_badg_vote_verybadg_votenoneg_mapname);
    
SQL_Execute(query);
    
SQL_FreeHandle(query);
    
    return 
PLUGIN_HANDLED;

Very thank's !
__________________
MiniBrackeur => Daminou
MiniBrackeur is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 02-21-2013 , 19:27   Re: Mysql result ?
Reply With Quote #2

You can do it without getting data from mysql like this:
PHP Code:
new Handle:g_sql_tuple
public sql_init()
{
    new 
sqlhostname[35], sqluser[35], sqlpass[35], sqldbname[35], errcodeerror[128];
    
get_cvar_string("amx_sql_host"sqlhostname34);
    
get_cvar_string("amx_sql_user"sqluser34);
    
get_cvar_string("amx_sql_pass"sqlpass34);
    
get_cvar_string("amx_sql_db"sqldbname34);
    
g_sql_tuple SQL_MakeDbTuple(sqlhostnamesqlusersqlpasssqldbname);
    
db SQL_Connect(g_sql_tupleerrcodeerrorcharsmax(error));
    return 
PLUGIN_CONTINUE;


public 
end_notemap() 
{
    new 
players[32], playerscount;
    
get_players(playersplayerscount"ch");
    for(new 
iplayerscounti++)
    {
        new 
id players[i];
        
menu_cancel(id);
    } 
    
    new 
cache[512]
    
formatex(cachesizeof(cache)-1"UPDATE `cs_notemap` SET `verygood`=`verygood`+'%d', `good`=`good`+'%d', `bad`=`bad`+'%d', `verybad`=`verybad`+'%d', `none`=`none`+'%d' WHERE `map`='%s'"result[0], result[1], result[2], result[3], result[4], g_mapname);
    
SQL_ThreadQuery(g_sql_tuple"qh_ignore"cache)
}

public 
qh_ignore(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(
FailState)
    {
        
log_amx("SQL Error: %s"Error)
        return
    }

__________________
Impossible is Nothing

Last edited by Sylwester; 02-21-2013 at 19:28.
Sylwester is offline
MiniBrackeur
Senior Member
Join Date: Oct 2010
Old 02-22-2013 , 06:01   Re: Mysql result ?
Reply With Quote #3

Oh I didn't know it, very thank's !
__________________
MiniBrackeur => Daminou
MiniBrackeur is offline
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 21:42.


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