SA-MP Forums Archive
MySQL problem - 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: MySQL problem (/showthread.php?tid=247707)



MySQL problem - Exxious - 10.04.2011

pawn Code:
public LoadStuff()
{
    new values[6];
    for(new i = 0; i < MAX_MISSIONS; i++)
    {
        new Query[256];
        format(Query, sizeof(Query), "SELECT * FROM `stuff` WHERE `Test` = '%i' ", i);
        mysql_query(Query);
        mysql_store_result();
        sscanf(Query, "p<|>ffffff", values);
        minfo[i][x1] = values[0];
        minfo[i][y1] = values[1];
        minfo[i][z1] = values[2];
        minfo[i][x2] = values[3];
        minfo[i][y2] = values[4];
        minfo[i][z2] = values[5];
        mysql_free_result();
    }
    Loadmstuff();
    return 1;
}
Printf always prints that the floats are always 0.000000 and I guess that the whole code returns 0.00000


Re: MySQL problem - Calgon - 10.04.2011

Because you're trying to return your query, which means that the string sscanf is parsing is always:
Quote:

SELECT * FROM `stuff` WHERE `Test` = '%i'

Use this function.


Re: MySQL problem - Exxious - 10.04.2011

Quote:
Originally Posted by Calg00ne
View Post
Because you're trying to return your query, which means that the string sscanf is parsing is always:


Use this function.
Thanks.
EDIT: I've just added mysql_fetch_row_format(Query); under the store result thingy, but still returns 0.00000.


Re: MySQL problem - royal_king - 10.04.2011

I've similiar problem too can you please help me when you got fixed


Re: MySQL problem - Calgon - 10.04.2011

Print the variable 'Query' and show me what returns.


Re: MySQL problem - Alby Fire - 10.04.2011

pawn Code:
public LoadStuff()
{
    new
        Float:values[6];
    for(new i = 0; i < MAX_MISSIONS; i++)
    {
        new Query[128];
        format(Query, sizeof(Query), "SELECT * FROM `stuff` WHERE `Test` = '%i' ", i);
        mysql_query(Query);
        mysql_store_result();
        sscanf(Query, "p<|>ffffff", values);
        minfo[i][x1] = values[0];
        minfo[i][y1] = values[1];
        minfo[i][z1] = values[2];
        minfo[i][x2] = values[3];
        minfo[i][y2] = values[4];
        minfo[i][z2] = values[5];
        mysql_free_result();
    }
    Loadmstuff();
    return 1;
}



Re: MySQL problem - Calgon - 10.04.2011

That too.


Re: MySQL problem - Exxious - 10.04.2011

Quote:
Originally Posted by Alby Fire
View Post
pawn Code:
public LoadStuff()
{
    new
        Float:values[6];
    for(new i = 0; i < MAX_MISSIONS; i++)
    {
        new Query[128];
        format(Query, sizeof(Query), "SELECT * FROM `stuff` WHERE `Test` = '%i' ", i);
        mysql_query(Query);
        mysql_store_result();
        sscanf(Query, "p<|>ffffff", values);
        minfo[i][x1] = values[0];
        minfo[i][y1] = values[1];
        minfo[i][z1] = values[2];
        minfo[i][x2] = values[3];
        minfo[i][y2] = values[4];
        minfo[i][z2] = values[5];
        mysql_free_result();
    }
    Loadmstuff();
    return 1;
}
It's still 0.000000

EDIT: Calg00ne:
printf("%d.",Query); = 83


Re: MySQL problem - JaTochNietDan - 10.04.2011

Time and time again I see people using queries in a loop, they are designed to be able to gather all of that information in a single query, rather than all of the queries you're doing here, depending on the value of MAX_MISSIONS. Why not just do 1 query and then work from that? There's no sense in calling multiple queries when you can just call one!

pawn Code:
public LoadStuff()
{
    new values[6];
    new Query[256];
    mysql_query("SELECT * FROM `stuff`");
    mysql_store_result();
    while(mysql_fetch_row(Query))
    {
        sscanf(Query, "p<|>ffffff", values);
        minfo[i][x1] = values[0];
        minfo[i][y1] = values[1];
        minfo[i][z1] = values[2];
        minfo[i][x2] = values[3];
        minfo[i][y2] = values[4];
        minfo[i][z2] = values[5];
    }
    mysql_free_result();
    Loadmstuff();
    return 1;
}
I also recommend printing the value of Query just before sscanf, to make sure you're using the correct sscanf parameters to un-format that string. I hope that helps!

(Additionally I don't think you need 256 characters for the result!)


Re: MySQL problem - Calgon - 10.04.2011

Quote:
Originally Posted by JaTochNietDan
View Post
Time and time again I see people using queries in a loop, they are designed to be able to gather all of that information in a single query, rather than all of the queries you're doing here, depending on the value of MAX_MISSIONS. Why not just do 1 query and then work from that? There's no sense in calling multiple queries when you can just call one!

pawn Code:
public LoadStuff()
{
    new values[6];
    new Query[256];
    mysql_query("SELECT * FROM `stuff`");
    mysql_store_result();
    while(mysql_fetch_row(Query))
    {
        sscanf(Query, "p<|>ffffff", values);
        minfo[i][x1] = values[0];
        minfo[i][y1] = values[1];
        minfo[i][z1] = values[2];
        minfo[i][x2] = values[3];
        minfo[i][y2] = values[4];
        minfo[i][z2] = values[5];
    }
    mysql_free_result();
    Loadmstuff();
    return 1;
}
I also recommend printing the value of Query just before sscanf, to make sure you're using the correct sscanf parameters to un-format that string. I hope that helps!

(Additionally I don't think you need 256 characters for the result!)
I was going to point that out, but I couldn't be bothered to explain it all.

Anyway, use that code, but change 'values' to a float.