Looping problem
#1

Hello, I'm currently having a problem with my looping to search through data in a mysql database.

I'm using a /vlist command to list what vehicles a user has, but it loops constantly at least 100 times and just outputs a load of useless information.

Код:
CMD:vlist(playerid, params[]){
	new query[500], i = 1;
	new string[128];
	format(query, sizeof(query),"SELECT * FROM pvehicles  WHERE owner='%s'",playerVariables[playerid][pNormalName]);
	mysql_query(query);
	mysql_store_result();
	while(mysql_get_field(query,"|"))
	{
		sscanf(query, "p<|>e<iiiiffffs[24]s[24]iiiiiii>", vehicleinfo[i]);
		format(string, sizeof(string),"id(%d) Name:[%s] Times Destroyed [%d]  ",i, vehicleinfo[i][Name],vehicleinfo[i][Destroyed]);
		printf("query: %s", query);
		SendClientMessage(playerid,COLOR_YELLOW2, string);
		i++;
	}
}
Reply
#2

Sometimes I wonder if people actually read their own code. If it's a problem with an endless loop, then where do you look? (That was a rhetorical question.)

First you consult the wiki for proper usage of a function: https://sampwiki.blast.hk/wiki/MySQL#mysql_fetch_field_row
Then you'll see that you're using the wrong function altogether.
Finally you'll notice that the function you need is: https://sampwiki.blast.hk/wiki/MySQL#mysql_fetch_row_format
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
Sometimes I wonder if people actually read their own code. If it's a problem with an endless loop, then where do you look? (That was a rhetorical question.)

First you consult the wiki for proper usage of a function: https://sampwiki.blast.hk/wiki/MySQL#mysql_fetch_field_row
Then you'll see that you're using the wrong function altogether.
Finally you'll notice that the function you need is: https://sampwiki.blast.hk/wiki/MySQL#mysql_fetch_row_format
Ah thanks a lot! As I stated in another thread, I'm new to this SAMP scripting and have has nothing but trouble with integrating it with SAMP over the past 2-3 weeks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)