0

HI
I have a while loop and it's a foreach in it.The while loop showes a query result but if there was a foreach in the while loop ,it's run just one time but if it isn't in it ,the while run untill fetching all the result but I want to have foreach in the while .How should do so?

Thanks

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by hno
0

Well without seeing your code I can only show some examples of proper usage:

<?php 
$myArray=array('aa','bb','cc','dd'); 
 while (list ($key, $val) = each ($myArray) ) echo $val; 
reset($myArray); 
 while (list ($key, $val) = each ($myArray) ) echo $val; 
?>
<?php
/* example 1 */

$i = 1;
while ($i <= 10) {
    echo $i++;  /* the printed value would be
                   $i before the increment
                   (post-increment) */
}

/* example 2 */

$i = 1;
while ($i <= 10):
    echo $i;
    $i++;
endwhile;
?>
0

Excuse me for the delay.I was so busy.
It's an example:

while($row=mysqli_fetch_assoc($r)){
   //some codes
   foreach($row['cat'] as $key=>$val){
         //some codes
   }
}

I'm sure that the while execute more that one time but It's just run one time and I know the reason is the foreach .How should use sole the problem.
Thanks

Edited by Reverend Jim: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.