2 MYSL queries at the same time - causing a problem?
#1

I have a piece of code which uses the next lines:

pawn Код:
mysql_query("SELECT * FROM `Houses`");
    mysql_store_result();
    if(mysql_num_rows() > 0)
    {
        while(mysql_fetch_row(Query))
        {
            totalHouses++;
            sscanf(Query, "e<p<|>dddffffffdddddddddddddddddddddddddd>", Houses[totalHouses]);
            GetPos2DZone(Houses[totalHouses][EnterX], Houses[totalHouses][EnterY], area, sizeof(area));
            if(Houses[totalHouses][IsOwned] == 1)
            {
                printf("OWNER ID: %d (Name: EMPTY)",Houses[totalHouses][OwnerID]);
                format(name, sizeof(name), "%s", GetAccountFromID(Houses[totalHouses][OwnerID]));

And this is GetAccountFromID:
pawn Код:
stock GetAccountFromID(id)
{
    new Query2[sizeof(Query)];
    new name[MAX_PLAYER_NAME];
    format(Query2, sizeof(Query), "SELECT `Username` FROM `Accounts` WHERE ID = '%d'", id);
    mysql_query(Query2);
    mysql_store_result();
    if(mysql_num_rows() > 0)
    {
        if(mysql_fetch_row(Query2))
        {
            sscanf(Query2, "s[20]",name);
        }
    }
    mysql_free_result();
    return name;
}
I'm having a problem with the first function, its like it doesn't take any action. When I remvoe the second function's like, it works perfectly.
Is there any problem using 2 MYSQL different queries at the same time? If so, what alternate way can I use?

Thank you.
Reply
#2

I can not use the main Query since I need it saved before I call the function.
"also change '%d' to %d" - No need.
"and s[20] to s[24] " - It has nothing to do with my problem, but still - done.

Anyone else?
Reply
#3

Yes there is a problem, that's why you should use LEFT JOIN here:
Quote:

SELECT gh.*, acc.Username AS ownername FROM Houses gh LEFT JOIN Accounts acc ON gh.OwnerID = acc.ID

Don't know if your field which holds owner's ID in Houses table is named OwnerID, but I suppose so. This query will select owner's name (if ownerID is connected to any account ID), otherwise "virtual" field ownername will be NULL.
Reply
#4

I'm really sorry but I didn't understand your given code, and what you wanted to say.
I'm trying to select the user's database ID name, and return it as a string. If I understood you correctly, what you are trying to do is to do that in one select line? Am I right?

If so, I didn't understand the MYSQL code. what is 'gh.', and 'acc.'? How should I define them?
Sorry for being dumby, but I'm not that familiar with this language.
Reply
#5

This is a forum for SA-MP scripting and not help with SQL queries. Sergei gave you code to fix it, you can ****** for more information on the code he provided if you're unsure of what it means.

You on the other hand had no right to spam this thread, you should have just waited and stop being an impatient idiot.
Reply
#6

Quote:
Originally Posted by _Tommy
Посмотреть сообщение
If so, I didn't understand the MYSQL code. what is 'gh.', and 'acc.'? How should I define them?
Sorry for being dumby, but I'm not that familiar with this language.
They are table tags. You should check MySQL documentation for more information about that.
And of course you are dumby since nobody with a bit of sense would do something like you do in your example.

Quote:
Originally Posted by Calg00ne
Посмотреть сообщение
You on the other hand had no right to spam this thread, you should have just waited and stop being an impatient idiot.
watch oot u can get infractionz!!!!11
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)