SA-MP Forums Archive
Looping problem - 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: Looping problem (/showthread.php?tid=418063)



Looping problem - Jonesy96 - 23.02.2013

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++;
	}
}



Re: Looping problem - Vince - 23.02.2013

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


Re: Looping problem - Jonesy96 - 23.02.2013

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.