SA-MP Forums Archive
Why the output returns -1 ? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Why the output returns -1 ? (/showthread.php?tid=72601)



Why the output returns -1 ? - gijsmin - 09.04.2009

pawn Код:
stock mysql_Int(db[],fl[],output,input[])
{
    new query[256],Result[256];
    format(query,sizeof(query),"SELECT %s FROM %s WHERE %s",fl,db,input);
    samp_mysql_query(query);
    samp_mysql_store_result();
    if(samp_mysql_fetch_row(Result)==1)
    {
      samp_mysql_fetch_row(Result);
        output=strval(Result);
        return output;
    }
    return 0;
}
if i do this: mysql_Int("users","id",playerinfo[playerid][uid],string); (string = `name`='%s') and then i print playerinfo[playerid][uid] then i see -1
But if i do this: printf("%d",mysql_Int("users","id",playerinfo[playerid][uid],string)) then i get the Real ID

How to fix it?


Re: Why the output returns -1 ? - tom_jonez - 09.04.2009

pawn Код:
stock mysql_Int(db[],fl[],input[])
{
    new query[256],Result[256],value[11]; //value is an integer so it doesnt have to be a large string.
    format(query,sizeof(query),"SELECT %s FROM %s WHERE %s",fl,db,input);
    samp_mysql_query(query);
    samp_mysql_store_result();
    if(samp_mysql_fetch_row(Result)==1)
    {
        samp_mysql_strtok(value,"|",Result);
        new output=strval(value);
        return output;
    }
    return 0;
}
Remove the output from the function line, no need for it. Tokenize it, grab the integer, return it. So it can return 100, 5, 26, or 1. Any integer up to 11 digits long. so 10000000000 is an 11 length integer. Now this should work. Now use:
pawn Код:
playerinfo[playerid][uid] = mysql_Int("users","id",string);



Re: Why the output returns -1 ? - gijsmin - 09.04.2009

I need to fix a script with this Bug !
and that script is 43560 lines with 200+ Mysql_Int


Re: Why the output returns -1 ? - tom_jonez - 09.04.2009

why doesnt my code work...


Re: Why the output returns -1 ? - gijsmin - 09.04.2009

Quote:
Originally Posted by R4nk3d
why doesnt my code work...
Because i want my code fixed not a other code


Re: Why the output returns -1 ? - tom_jonez - 09.04.2009

Quote:
Originally Posted by Gijsmin (Spot-Host.co.uk)
Quote:
Originally Posted by R4nk3d
why doesnt my code work...
Because i want my code fixed not a other code
this is the fixed code.... ur code didnt make sense and this is the revised code that will work.


Re: Why the output returns -1 ? - gijsmin - 09.04.2009

TOPIC SOLVED