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

Recommended Answers

All 3 Replies

Would you please show us your code

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;
?>

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.