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.
For/While Loop
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: For/While Loop
***** PLEASE USE THE
Code: Select all
TAG WHEN POSTING ******[/color]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
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.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 } } } ?>
Re: For/While Loop
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.
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.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: For/While Loop
You really don't need to for loop. Just LIMIT the number of results being returned by the query and use the while loop.
(#10850)