Raised This Month: $ Target: $400
 0% 

Wrong reading from SQL


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 06-03-2010 , 13:04   Wrong reading from SQL
Reply With Quote #1

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".

Last edited by Backstabnoob; 06-03-2010 at 13:08.
Backstabnoob is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 06-03-2010 , 16:11   Re: Wrong reading from SQL
Reply With Quote #2

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 ?
__________________
Impossible is Nothing
Sylwester is offline
Reply


Thread Tools
Display Modes

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 05:27.


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