Page 1 of 1

class array not being defined

Posted: Wed Jun 25, 2003 2:38 pm
by kendall
hello,

i have the following code which selects information from a databse and stores it in an array clas var

Code: Select all

$Children = mysql_query($Query, $Connection) or die(mysql_error());
					$Child = mysql_fetch_assoc($Children);
					if(mysql_num_rows($Children)>0){
							do{
								echo $Child['INDID'].' - '.$Child['FName'].' '.$Child['MName'].' '.$Children['LName'];
								$this->Children = array($Child['INDID']=>$Child['FName'].' '.$Child['MName'].' '.$Child['LName']);
							}while($Child = mysql_fetch_assoc($Children));
					}
My problem is while im able to print the returned query info only one set of it is sotred in the array $this->Children

no i know for a fact (tru debuggin) that there are 2 rows of result...why am i getting only one value in the array when i

foreach($children as child) echo child?

Kendall

Posted: Wed Jun 25, 2003 3:32 pm
by Galahad
The line:

Code: Select all

<?php
$this->Children = array($Child['INDID']=>$Child['FName'].' '.$Child['MName'].' '.$Child['LName']);
?>
sets $this->Children to be a new array with only 1 element each time it gets executed. As a result, the loop ends with $this->Children containing only the last one. Perhaps you want something like:

Code: Select all

<?php
$this->Children[$Child['INDID']] = $Child['FName'].' '.$Child['MName'].' '.$Child['LName'];
?>