08-30-2009, 05:36 PM
|
#1 (permalink)
|
|
The Acquainted
Join Date: Apr 2008
Posts: 110
Thanks: 97
|
While loop is over my head
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 = 1 ;
[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
Last edited by codefreek : 09-01-2009 at 05:32 PM.
Reason: php tags added, please read note, Thank you!
|
|
|
|