Raised This Month: $ Target: $400
 0% 

Select More than 1 data Mysql


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
StickP0le
Senior Member
Join Date: Jan 2010
Location: cuantocabron.com
Old 01-20-2012 , 00:03   Select More than 1 data Mysql
Reply With Quote #1

Ok im making a top15 in my server and it only select one column is there any way to select more than one data this is my code
Code:
 // Connect to SQL     new Handle:SqlConnect = SQL_Connect(g_hTuple, ErrorCode, g_Error, 511)         if(SqlConnect == Empty_Handle)     {         log_amx("SQL Error: %s", g_Error)         set_fail_state(g_Error)         return PLUGIN_HANDLED;     }         static nombre[33], kills, infectados         // Create Handle     new Handle:Query     Query = SQL_PrepareQuery(SqlConnect, "SELECT `Nombre`, `Kills`, `Infectados` FROM `personajes` ORDER BY `Kills` DESC LIMIT 50")         if (SQL_Execute(Query))     {         if (SQL_NumResults(Query))         {             SQL_ReadResult(Query, 0, nombre, charsmax(nombre))             kills = SQL_ReadResult(Query, 1)             infectados = SQL_ReadResult(Query, 2)                     }     }
StickP0le is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 01-20-2012 , 00:14   Re: Select More than 1 data Mysql
Reply With Quote #2

PHP Code:
 // Connect to SQL
    
new Handle:SqlConnect SQL_Connect(g_hTupleErrorCodeg_Error511)
    
    if(
SqlConnect == Empty_Handle)
    {
        
log_amx("SQL Error: %s"g_Error)
        
set_fail_state(g_Error)
        return 
PLUGIN_HANDLED;
    }
    
    static 
nombre[50][33], kills[50], infectados[50]
    new 
cnt
    
    
// Create Handle
    
new Handle:Query
    Query 
SQL_PrepareQuery(SqlConnect"SELECT `Nombre`, `Kills`, `Infectados` FROM `personajes` ORDER BY `Kills` DESC LIMIT 50")
    
    if (
SQL_Execute(Query))
    {
        while (
SQL_MoreResults(Query))
        {
            
SQL_ReadResult(Query0nombre[cnt], charsmax(nombre[]))
            
kills[cnt] = SQL_ReadResult(Query1)
            
infectados[cnt] = SQL_ReadResult(Query2)
            
cnt++
            
SQL_NextRow(Query)
        }
    } 
__________________
Impossible is Nothing

Last edited by Sylwester; 01-20-2012 at 00:15.
Sylwester is offline
StickP0le
Senior Member
Join Date: Jan 2010
Location: cuantocabron.com
Old 01-20-2012 , 00:21   Re: Select More than 1 data Mysql
Reply With Quote #3

thanks man you are the best

Last edited by StickP0le; 01-20-2012 at 00:34.
StickP0le is offline
StickP0le
Senior Member
Join Date: Jan 2010
Location: cuantocabron.com
Old 01-20-2012 , 00:34   Re: Select More than 1 data Mysql
Reply With Quote #4

EDIT: im getting this error
Code:
  L 01/20/2012 - 02:30:22: [MySQL] Invalid column: 2 L 01/20/2012 - 02:30:22: [AMXX] Displaying debug trace (plugin "zombie_plague40.amxx") L 01/20/2012 - 02:30:22: [AMXX] Run time error 10: native error (native "SQL_ReadResult") L 01/20/2012 - 02:30:22: [AMXX]    [0] zombie_plague40.sma::show_menu_jugadores (line 10862)
StickP0le is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 01-20-2012 , 01:01   Re: Select More than 1 data Mysql
Reply With Quote #5

It means that you used SQL_ReadResult(Query, 2) to read results of a query that returned less than 3 columns.
__________________
Impossible is Nothing
Sylwester is offline
StickP0le
Senior Member
Join Date: Jan 2010
Location: cuantocabron.com
Old 01-20-2012 , 01:16   Re: Select More than 1 data Mysql
Reply With Quote #6

ok, thanks man iŽll try adding more columns to the database

Last edited by StickP0le; 01-20-2012 at 01:17.
StickP0le is offline
StickP0le
Senior Member
Join Date: Jan 2010
Location: cuantocabron.com
Old 01-20-2012 , 01:22   Re: Select More than 1 data Mysql
Reply With Quote #7

i tried adding one more column and still get this error
StickP0le is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 01-20-2012 , 01:47   Re: Select More than 1 data Mysql
Reply With Quote #8

It's not about how many columns you have in database table, but how many you retrieve with query.
PHP Code:
SELECT `col1FROM `table_name` ... //<-- this retrieves data only from 1 column
SELECT `col1`,`col2`,`col3FROM `table_name`... //<-- this retrieves data from 3 columns
SELECT FROM `table_name` ... //<-- this retrieves data from all columns 
__________________
Impossible is Nothing

Last edited by Sylwester; 01-20-2012 at 01:47.
Sylwester is offline
StickP0le
Senior Member
Join Date: Jan 2010
Location: cuantocabron.com
Old 01-20-2012 , 02:14   Re: Select More than 1 data Mysql
Reply With Quote #9

ohh, my bad, i will try that
StickP0le 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 12:54.


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