AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Wrong reading from SQL (https://forums.alliedmods.net/showthread.php?t=128639)

Backstabnoob 06-03-2010 13:04

Wrong reading from SQL
 
PHP Code:

    new Data[1]
    
Data[0] = id
    
    format
(g_Query4095"SELECT * from arp_familybank WHERE Familyname='%s'"g_FamilyName[id])
    
SQL_ThreadQuery(g_SqlHandle,"LoadBank",g_Query,Data,1

PHP Code:


public LoadBank(FailStateHandle:QueryError[], ErrcodeData[], Datasizeid)
{
    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("Internal error: consult developer.")
   
    if(
Errcode)
        return 
log_amx("Error on query: %s",Error)

    
id Data[0]
    
    new 
PlatBankmoney
    
    
while(SQL_MoreResults(Query))
    {
        
SQL_ReadResult(Query1Bankmoney)
        
SQL_ReadResult(Query2Plat)
        
        
g_BankMoney[id] = Bankmoney
        g_BankPlat
[id] = Plat
        
        SQL_NextRow
(Query)
    }
    
    for(new 
xx<33x++)
        if(
g_IsInFamily[x] && equali(g_FamilyName[id], g_FamilyName[x]))
        {
            
g_BankPlat[x] = Plat
            g_BankMoney
[x] = Bankmoney
        
}
        
    return 
PLUGIN_CONTINUE


This somehow reads the result badly. Plat and Bankmoney are like 12561268646, but it has to be for example 1000. In table it's okay, but, as I said, it reads it badly. I don't know why, at first I thought it takes the result as a string, but it doesn't from what I've read. str_to_num() doesn't work.

Edit:

The table structure is like this:

CREATE TABLE IF NOT EXISTS arp_familybank (Familyname VARCHAR(36), Stav VARCHAR(10), Plat VARCHAR(10), PRIMARY KEY (Familyname))

I want to return second column into "Bankmoney" and third one into "Plat".

Sylwester 06-03-2010 16:11

Re: Wrong reading from SQL
 
try:
PHP Code:

    new Plat[12], Bankmoney[12]
    
    while(
SQL_MoreResults(Query))
    {
        
SQL_ReadResult(QuerySQL_FieldNameToNum(Query,"Stav"), Bankmoney11)
        
SQL_ReadResult(QuerySQL_FieldNameToNum(Query,"Plat"), Plat11)
        
        
g_BankMoney[id] = str_to_num(Bankmoney)
        
g_BankPlat[id] = str_to_num(Plat)
        
        
SQL_NextRow(Query)
    } 

Why do you store it in VARCHAR(10) and not integer ?


All times are GMT -4. The time now is 05:27.

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