Jump to content

While Statement


user4fun
 Share

Recommended Posts

I am trying to make certain actions take place for the first 3 rows found and then other actions for the other rows from 4 to 6. This is what I have so far. I am not being able to test it at this time. Can anyone see why it might not work?.

Function WeHave($result){global $num_rows;global $result;$num_rows = mysql_num_rows($result);$i = 1;while($foundrow = mysql_fetch_array($result))	   {	 echo $i " - ";	 echo $foundrow['FirstName'] . " " . $foundrow['USERID'];	 echo "<br />"; 	 $i++;	 if ($1==4)			  {				   echo $num_rows . " RESULTS were found but we have to do something else starting at row 4"; 				  					for ($i=4; $i<=6; $i++)					   {				 echo $foundrow['FirstName’] . " " . $foundrow['LastName'];				   echo "<br />"; 						}			  }  	   }echo " If you reached this. It means that ONLY 3 or less results were found.";echo " We had " $num_rows;}

Link to comment
Share on other sites

I would not be using the While clause there. Ypu would be better off using a single for-loop and handling the first three in one manner, the next three in a second manner.Also, do you have a LIMIT clause on the Mysql query? Since you are dealing with only the first 6 rows, just place a limit on the number of returned rows in the Query.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...