(mysql) Select 5 random houseid's without calling the query 5 times? - 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) Select 5 random houseid's without calling the query 5 times? (
/showthread.php?tid=266899)
(mysql) Select 5 random houseid's without calling the query 5 times? Edited^^ -
Donya - 06.07.2011
wait! i have another quick question, how would i make it not select 2 same houseid's in the same query? if it can't be done in the same query.. i'll do it the longer way then
Re: (mysql) Select 5 random houseid's without calling the query 5 times? -
Calgon - 06.07.2011
Have you tried changing the limit to 5 instead of 1? I'd have assumed that would've been the most obvious way.
Re: (mysql) Select 5 random houseid's without calling the query 5 times? -
Donya - 06.07.2011
oh yea o.o, so then i would have to split it with sscanf?..right
Re: (mysql) Select 5 random houseid's without calling the query 5 times? -
Calgon - 06.07.2011
pawn Код:
new szLine[120]; // though you'll probably need a ridiculous size for the line
while(mysql_retrieve_row_format(szLine)) {
// do your magic with sscanf here
}
while will execute for every result it retrieves, so 5 if you limit your query to 5.
Re: (mysql) Select 5 random houseid's without calling the query 5 times? -
Donya - 06.07.2011
Edit: i see what i did wrong, thanks.
pawn Код:
mysql_query("SELECT `Houseid` FROM `Houses` WHERE `Owner` != 'Unbought' ORDER BY RAND() LIMIT 5");
mysql_store_result();
new Query[16], m_Houseid[5];
while(mysql_fetch_row_format(Query))
{
static c_House = 0;
sscanf(Query, "p<|>i", m_Houseid[c_House]);
c_House++;
}
printf("H1: %d - H2: %d - H3: %d - H4: %d - H5: %d - Query: %s", m_Houseid[0], m_Houseid[1], m_Houseid[2], m_Houseid[3], m_Houseid[4], Query);
worked perfectly
Re: (mysql) Select 5 random houseid's without calling the query 5 times? -
Donya - 06.07.2011
ah, i see. that worked perfectly too! thanks.
pawn Код:
mysql_query("SELECT `Houseid` FROM `Houses` WHERE `Owner` != 'Unbought' ORDER BY RAND() LIMIT 7");
mysql_store_result();
new Query[8], m_Houseid[7];
while(mysql_fetch_row_format(Query))
{
static c_House = 0;
m_Houseid[c_House] = strval(Query);
c_House++;
}
printf("H1: %d - H2: %d - H3: %d - H4: %d - H5: %d - H6: %d - H7: %d", m_Houseid[0], m_Houseid[1], m_Houseid[2], m_Houseid[3], m_Houseid[4], m_Houseid[5], m_Houseid[6]);
Re: (mysql) Select 5 random houseid's without calling the query 5 times? -
Donya - 06.07.2011
yes, the result is free'd after the print.
edit: wait! i have another quick question, how would i make it not select 2 same houseid's in the same query? if it can't be done in the same query.. i'll do it the longer way then