AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   sqlx my code wrong ? (https://forums.alliedmods.net/showthread.php?t=82596)

DaniDin 12-26-2008 10:15

sqlx my code wrong ?
 
hi i have db and table with the name "tbname" and column "name"
when i do this
PHP Code:

public client_disconnect(id)
    
SQL_ThreadQuery(g_SqlTuple,"SelectHandle","SELECT name FROM tbname WHERE id='1'")

    
public 
SelectHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(
FailState == TQUERY_CONNECT_FAILED)
        return 
set_fail_state("Could not connect to SQL database.")
    else if(
FailState == TQUERY_QUERY_FAILED)
        return 
set_fail_state("Query failed.")
   
    if(
Errcode)
        return 
log_amx("Error on query: %s",Error)
   
    new 
DataNum
    
while(SQL_MoreResults(Query))
    {
        
DataNum SQL_ReadResult(Query,0)
       
        
server_cmd("amx_say your name is %d ",DataNum)
    
        
SQL_NextRow(Query)
    }
   
    return 
PLUGIN_CONTINUE


i get like this : your name is 0
but i have the name "loler"
and i want that print this "Your name is loler"

SnoW 12-26-2008 10:17

Re: sqlx my code wrong ?
 
Code:

server_cmd("amx_say your name is %d ",DataNum)
How that could even print a string? :)

DaniDin 12-26-2008 10:21

Re: sqlx my code wrong ?
 
><
so ? lol
i try %s it's not work too

DaniDin 12-26-2008 10:24

Re: sqlx my code wrong ?
 
when i do %s it's print null ("")

SnoW 12-26-2008 10:26

Re: sqlx my code wrong ?
 
Double post?? -/-
Code:

new DataNum[33];


DaniDin 12-26-2008 10:31

Re: sqlx my code wrong ?
 
sorry for the double i use ff so not all the picture show where they need ...
and i do what you say and it say
Error: Array must be indexed (variable "DataNum") on line 95

SnoW 12-26-2008 10:36

Re: sqlx my code wrong ?
 
Ye but, look... You have to understand the difference between int and string. When you create new String[33] you have to use index there, like String[id] = "bllaaabla". Ofc when you read someone name get_user_name(id, String, 32), it's not needed because there is id on the native...

DaniDin 12-26-2008 10:46

Re: sqlx my code wrong ?
 
:\
i dont understated you can help me pls ? :(

DaniDin 12-26-2008 11:31

Re: sqlx my code wrong ?
 
omg success
PHP Code:

public SelectHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(
FailState == TQUERY_CONNECT_FAILED)
        return 
set_fail_state("Could not connect to SQL database.")
    else if(
FailState == TQUERY_QUERY_FAILED)
        return 
set_fail_state("Query failed.")
   
    if(
Errcode)
        return 
log_amx("Error on query: %s",Error)
   
    new 
DataNum
    
new str[33]
    while(
SQL_MoreResults(Query))
    {
        
DataNum SQL_ReadResult(Query,0,str,33)
       
        
server_cmd("amx_say some data: %s ",str)
    
        
SQL_NextRow(Query)
    }
   
    return 
PLUGIN_CONTINUE


thanks :D

Spunky 12-26-2008 13:50

Re: sqlx my code wrong ?
 
PHP Code:

DataNum SQL_ReadResult(Query,0,str,33

Completely unnecessary because DataNum is never used. Just use:

PHP Code:

SQL_ReadResult(Query,0,str,33



All times are GMT -4. The time now is 09:16.

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