class array not being defined

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

class array not being defined

Post 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
Galahad
Forum Contributor
Posts: 111
Joined: Fri Jun 14, 2002 5:50 pm

Post 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'];
?>
Post Reply