Two Questions Re: Child-Parent Script

message from David B on 23 Jul 2004
This script appears to work quite well. It prints out every mammal
order, family, genus and species - and surprisingly rapidly. But the
display alternates data with the error message "Warning: Invalid
argument supplied for foreach() in C:\sites\freedomware\axis.php on line
127."

Do you know how to fix that?

Also, the names print out horizontally across the screen, exactly like this:

Mammalia Monotremata Tachyglossidae Tachyglossus aculeatus

Do you know of a way to somehow identify and manipulate names of a
particular hierarchy? For example, I'd like to indent the names, so they
look like this:

Carnivora
Felidae
Panthera
tigris

Thus, I'd have to instruct each FAMILY name to indent so many spaces.
And if I could accomplish that, then I might be able to modify the font,
background color, etc.

Thanks.

Here's a portion of the display...

Mammalia Monotremata Tachyglossidae Tachyglossus aculeatus
Warning: Invalid argument supplied for foreach() in
C:\sites\freedomware\axis.php on line 127
Zaglossus bruijni
Warning: Invalid argument supplied for foreach() in
C:\sites\freedomware\axis.php on line 127
Ornithorhynchidae Ornithorhynchus anatinus
Warning: Invalid argument supplied for foreach() in
C:\sites\freedomware\axis.php on line 127
Didelphimorphia Didelphidae Caluromyinae
Warning: Invalid argument supplied for foreach() in
C:\sites\freedomware\axis.php on line 127
Didelphinae
Warning: Invalid argument supplied for foreach() in
C:\sites\freedomware\axis.php on line 127
Caluromys derbianus

Here's the script...

[PHP]
<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
[DATABASE CONNECTION]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
<html xmlns="http://www.w3.org/1999/xhtml"
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>

<?php

function display_children($parent = '', $level = 0)
{
global $nodes;
if ($parent) {
echo str_repeat(' ', $level), $parent, "\n";
}
foreach ($nodes[$parent] as $child) {
display_children($child, $level + 1);
}
$nodes = array();
$result = mysql_query('SELECT FamMamParent, FamMamName FROM fammammals');
while ($row = mysql_fetch_assoc($result)) {
$nodes[$row['FamMamParent']][] = $row['FamMamName'];
}
display_children();
?>

</body>
</html>
[/PHP]
 
Jason Dalgarno replied to David B on 24 Jul 2004
display_errors must be turned off in my head.

You want
if (isset($nodes[$parent])) {
...
around the foreach.
 
Murray *TMM* replied to Jason Dalgarno on 24 Jul 2004
Nice one. How you do that?
 
David B replied to Jason Dalgarno on 24 Jul 2004
Yes, that fixed it, thanks. I wish you had written the tutorial!
 

Archived message: Two Questions Re: Child-Parent Script (Macromedia Dreamweaver Web Design)