Page 1 of 1
For/While Loop
Posted: Sun Feb 03, 2008 10:28 pm
by kerepuki
Hey guys, first post here in a long time. I am doing quite a bit of coding lately and have come across a small (and hopefully easy) problem.
I have a for loop (for($i = 0; $i <= 5; $i++) etc) and inside this for loop I have a while/fetch array statement.
My problem is that my for loop is ignored. Why would this be?
Thanks in advance.
Re: For/While Loop
Posted: Sun Feb 03, 2008 11:12 pm
by Christopher
You would need to post some code.
Re: For/While Loop
Posted: Mon Feb 04, 2008 5:53 pm
by kerepuki
***** PLEASE USE THE Code: Select all
<?php
for($c = 0; $c <= 5; $c++){
while($data_row_c = mysql_fetch_array($data_query_c)){
$item_row_c = mysql_fetch_array($item_query_c);
if($active_row_c['confirmed'] == 1){
?>
<!--THEN MY CODE TO DISPLAY RESULTS-->
<?php
}
}
}
?>
Re: For/While Loop
Posted: Mon Feb 04, 2008 6:37 pm
by califdon
kerepuki wrote:***** PLEASE USE THE TAG WHEN POSTING ******
Code: Select all
<?php
for($c = 0; $c <= 5; $c++){
while($data_row_c = mysql_fetch_array($data_query_c)){
$item_row_c = mysql_fetch_array($item_query_c);
if($active_row_c['confirmed'] == 1){
?>
<!--THEN MY CODE TO DISPLAY RESULTS-->
<?php
}
}
}
?>
I'd say either no rows were returned by your query (did you test it to see?) or the $active_row_c['confirmed'] doesn't equal 1.
Re: For/While Loop
Posted: Mon Feb 04, 2008 10:32 pm
by kerepuki
Thanks for the reply, yes I can see my results and the correct results are being displayed however, there are too many of them. I dont want to create a pagination scenario so I thought that it would be ok to create a for loop to only display 5 rows.
It doesnt matter too much, I can just recreate the loop another way if its going to take too much time to solve.
Just seems weird that it wont only display 5 results.
Re: For/While Loop
Posted: Tue Feb 05, 2008 12:08 am
by Christopher
You really don't need to for loop. Just LIMIT the number of results being returned by the query and use the while loop.