View Single Post
Old 08-31-2009, 08:17 AM   #4 (permalink)
RishikeshJha
The Wanderer
 
Join Date: May 2009
Posts: 6
Thanks: 0
RishikeshJha is on a distinguished road
Default

Quote:
Originally Posted by Dave View Post
Hi,

The WHILE and FOREACH loops below are elementary, yet how they work keeps evading my mental grasp. Here is a UDF:

PHP Code:
$c_pettype "horse" ;
 
 function 
getpets($c_pettype)
 {
 
  
$q "SELECT *
       FROM t_petdata
         WHERE pettype = '
$c_pettype'" ;
          
 
$result mysql_query($q) or die ('bad query') ;

 
$j ;

 [
color="Red"]while($row mysql_fetch_assoc($result))[/color]
 { 
     [
color="Red"]foreach($row as $key => $value)[/color]
     {
         
$array[$j][$key] = $value ;
     }
                
     return 
$array ;
 }
 

So, I get the arrays, and the general concept of looping, etc., but the concepts of "WHILE($row = ...)" and "FOREACH($row as...) are not clear to me. I mean, where does "$row" come from?

Is there a way to help me understand this on a simple level?

Thanks!

Dave
$row contains the value that is assigned mysql_fetch_assoc($result).

Last edited by codefreek : 09-01-2009 at 05:33 PM.
RishikeshJha is offline  
Reply With Quote
The Following User Says Thank You to RishikeshJha For This Useful Post:
Dave (09-02-2009)