08-31-2009, 08:17 AM
|
#4 (permalink)
|
|
The Wanderer
Join Date: May 2009
Posts: 6
Thanks: 0
|
Quote:
Originally Posted by Dave
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
|
$row contains the value that is assigned mysql_fetch_assoc($result).
Last edited by codefreek : 09-01-2009 at 05:33 PM.
|
|
|
|