(mysql) Select 5 random houseid's without calling the query 5 times?
#1

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
Reply
#2

Have you tried changing the limit to 5 instead of 1? I'd have assumed that would've been the most obvious way.
Reply
#3

oh yea o.o, so then i would have to split it with sscanf?..right
Reply
#4

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.
Reply
#5

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
Reply
#6

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]);
Reply
#7

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
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)