Page 1 of 1

iterating a for loop

Posted: Thu Jul 01, 2004 3:42 am
by ruud
hi there

i would like to know how i can break out of a 'for' loop and tell it to start again with the next iteration.

for example i am using the code below to loop through an array of results i have previously got from a table and then use the returned rows to execute a series of sql statements.

Code: Select all

for ($count=0; $row=mysql_fetch_array($ID_array); $count++)


	{

		$conn = OpenDBConnection();

		$selprod = "select * from Products where ProductID = " .$rowї'ProductID']. " and Discontinued = 'False'";
				
		$result = mysql_query ($selprod, $conn) or die(mysql_error());

		$row_result = mysql_num_rows ($result);
		
		CloseDBConnection($conn);
		
	
if  ($row_result >= 1)

				{ //code in here where i want it to break out of function and  loop on to the next iteration }
				
				
					else {
if the sql query shown returns a row then i want it to break out of the function and move on to the next iteration of the 'for' loop. If it doesn't return a row then i want it to carry on with the rest of the function contained after 'else {' and when it's completed the function then move on to the next iteration of the 'for' loop!

Thanks in advance for any help :)

Posted: Thu Jul 01, 2004 4:16 am
by Grim...
You need [php_man]continue[/php_man]();

Also works in while loops.

Posted: Thu Jul 01, 2004 5:51 am
by ruud
thanks for replying - all works well now!! :)

Posted: Thu Jul 01, 2004 6:26 am
by Grim...
SOLVED!

Another one chalked on the board for Grimmeh :D