Trying to make site map

[email protected] (Zach Hicken)
Newsgroups php.db
Message-ID <[email protected]>
I am trying to create a ui for a page management script. During this  
step the user chooses which existing page the new page will link  
under. Each record has a field called Page_Above, which references the  
primary key number (id) of the page above it. Currently I have 4  
records in the database:
(id, name, Page_Above)
1, Page1, 0
2, Page2, 1
3, Page3, 2
4, Page4, 1

Here is the pertinent snippet:

		
				include "config.php";
				$conn = mysql_connect($server, $DBusername, $DBpassword);
				mysql_select_db($database,$conn);
				$sql = "SELECT * FROM $Gen WHERE Category = '$Cat' AND Page_Above  
= 0";
				$result = mysql_query($sql, $conn) or die(mysql_error());
				//go through each row in the result set and display data
				while ($pageArray = mysql_fetch_array($result)) {
					
					$prime_id  = $pageArray['id'];
					$Name = $pageArray['Name'];
					print ("<tr><td bgcolor=#ffffff>$Name</td><td bgcolor=#ffffff  
align=left valign=top>");
					
				
							$sql = "SELECT * FROM $Gen WHERE Page_Above = $prime_id";
							$result = mysql_query($sql, $conn) or die(mysql_error());
							//go through each row in the result set and display data
							while ($secpageArray = mysql_fetch_array($result)) {
								// give a name to the fields
								$second_id  = $secpageArray['id'];
								$Name = $secpageArray['Name'];
								print ("$Name<br>");
								
								
							$sql = "SELECT * FROM $Gen WHERE Page_Above = $second_id";
							$result = mysql_query($sql, $conn) or die(mysql_error());
							//go through each row in the result set and display data
							while ($thpageArray = mysql_fetch_array($result)) {
								// give a name to the fields
								$third_id  = $thpageArray['id'];
								$Name = $thpageArray['Name'];
								print ("</td><td>");
								print ("$Name<br>");
								
								
							}
						
						}
					
					}

The results I am getting are incomplete, it only pulls one page per  
level instead of all the pages per level, Like this:
"Page1, Page 2, Page3"
it skips Page4.

When I remove the request for the third level, then I get:
"Page1,Page2,Page4"  Which is correct up to that point. It breaks  
apart when I try to go on the third level.

Any ideas how I can get this to work? In the end there will be 5 levels.
Thanks
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.