SA-MP Forums Archive
A better way of doing this query? - 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)
+--- Thread: A better way of doing this query? (/showthread.php?tid=531383)



A better way of doing this query? - arko123 - 12.08.2014

Is there a better way of doing this query?

pawn Код:
mysql_format(Connection, Query, sizeof Query, "SELECT `name` FROM `characters` WHERE `id` = %d LIMIT 1", MasterAccounts[playerid][maCharacter][0]);
mysql_function_query(Connection, Query, true, "SelectCharacterNames", "d", playerid);

mysql_format(Connection, Query, sizeof Query, "SELECT `name` FROM `characters` WHERE `id` = %d LIMIT 1", MasterAccounts[playerid][maCharacter][1]);
mysql_function_query(Connection, Query, true, "SelectCharacterNames", "d", playerid);

mysql_format(Connection, Query, sizeof Query, "SELECT `name` FROM `characters` WHERE `id` = %d LIMIT 1", MasterAccounts[playerid][maCharacter][2]);
mysql_function_query(Connection, Query, true, "SelectCharacterNames", "d", playerid);

mysql_format(Connection, Query, sizeof Query, "SELECT `name` FROM `characters` WHERE `id` = %d LIMIT 1", MasterAccounts[playerid][maCharacter][3]);
mysql_function_query(Connection, Query, true, "SelectCharacterNames", "d", playerid);
What I am doing is selecting the character name for four slots where the master account id matches.


Re: A better way of doing this query? - Misiur - 12.08.2014

pawn Код:
mysql_format(Connection, Query, sizeof Query, "SELECT `name` FROM `characters` WHERE `id` IN (%d, %d, %d, %d)", MasterAccounts[playerid][maCharacter][0], MasterAccounts[playerid][maCharacter][1], MasterAccounts[playerid][maCharacter][2], MasterAccounts[playerid][maCharacter][3]);
mysql_function_query(Connection, Query, true, "SelectCharacterNames", "d", playerid);
Then loop through rows and compare 'id' with MasterAccounts[playerid][maCharacter][x] to correlate slot with row.


Re: A better way of doing this query? - arko123 - 12.08.2014

Quote:
Originally Posted by Misiur
Посмотреть сообщение
pawn Код:
mysql_format(Connection, Query, sizeof Query, "SELECT `name` FROM `characters` WHERE `id` IN (%d, %d, %d, %d)", MasterAccounts[playerid][maCharacter][0], MasterAccounts[playerid][maCharacter][1], MasterAccounts[playerid][maCharacter][2], MasterAccounts[playerid][maCharacter][3]);
mysql_function_query(Connection, Query, true, "SelectCharacterNames", "d", playerid);
Then loop through rows and compare 'id' with MasterAccounts[playerid][maCharacter][x] to correlate slot with row.
Cheers.


Re: A better way of doing this query? - arko123 - 13.08.2014

I need a little help with the second part of what Misiur said, I have this so fair:
pawn Код:
public SelectCharacterNames(playerid)
{
    new
        Rows,
        Fields;

    cache_get_data(Rows, Fields);

    while(Rows)
    {

    }
    return 1;
}
I just don't know what to do after that.