One result, instead of several
#1

pawn Код:
while(mysql_fetch_row_format(data))
{
sscanf(data, "p<|>dd", rankid, orgid);

format(equery, sizeof(equery), "SELECT `Name` FROM `Organizations` WHERE `UID` = '%d'", orgid);
mysql_query(equery);
mysql_store_result();
mysql_fetch_row_format(name);
mysql_free_result();
               
format(equery, sizeof(equery), "SELECT `Name` FROM `Org_Ranks` WHERE `UID` = '%d'", rankid);
mysql_query(equery);
mysql_store_result();
mysql_fetch_row_format(rankname);
mysql_free_result();
               
format(string, sizeof(string), "%s\n%s (Ranks: %s)", string, name, rankname);
}
Why the string array returns only one result, but should be more
Reply
#2

hm... not sure but maybe it's because you are using new queries and new mysql_store_result and mysql_free_result within the loop... So the mysql row is a different one for the next time..
Reply
#3

Quote:
Originally Posted by Sascha
Посмотреть сообщение
hm... not sure but maybe it's because you are using new queries and new mysql_store_result and mysql_free_result within the loop... So the mysql row is a different one for the next time..
And how do I fix this?
Reply
#4

maybe use a for loop?
something like this:
rough example:
pawn Код:
#define MAX_ORGS 100


for(new n=0; n<MAX_ORGS; n++)
{
   //your query + mysql_store_result;
   if(mysql_num_rows() == 0)
   {
      mysql_free_result();
      goto conti;
   }
   else
   {
      //your code
    }
}
conti:
 return 1;
so in this example the loop runs 100 times..
each time you should select the orgid and rankid... and use it.. if it doesn't exist anymore, just use "goto conti" which will end the loop...
you might need something else as mysql_num_rows, although you should figure that out on your own with this basic example...
if not, just reply and I'll try it for you... although that will require the code of the first query, too
Reply
#5

Sascha, I think it is too charge for the server. You can not do it differently?
Reply
#6

Any help ?
Reply
#7

na it's not leny...
'cause it doesn't run 100 times..
it just runs as often until the result of the format or the numbers of found fields in the mysql query is not 0

As soon as the db is out of lines the loop stops (because of the goto)
All you do is just use the mysql_num_rows or mysql_row_format or w/e.. find out which fits best for you (although I guess the row format does)

the loop itself does exactly the same amount of runs as the while loop does
Reply
#8

y u no use break; instead of silly goto?
Reply
#9

depends on the code he wants to use...
he can use both, I just had goto in mind lol.. although it doesn't matter at all...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)