Ok, My table data is as follows
*table data isn't formatting properly, you can see it at;
http://www.hksinc.co...in/all_data.php
___________________________________________
page_id page_title page_parent_id page_order
1 Home 0 1
2 Architectural Visualization 0 2
30 Web Design 0 3
32 HKS, Inc. 0 4
31 Contact Us 1 1
37 Tridot 2
29 Rendering 2 1
3 Animation 2 2
33 Staff 2 5
38 Design Sub 1 22
41 Production Sub 1 27
22 Design 30 1
27 Production 30 2
39 Design Sub 2 (link) 38
42 Design Sub 2b 38
40 Design Sub 3 39
___________________________________________
My goal is for my page to display the following and have infinite parent-child levels.
___________________________________________
Home
Contact US
Architectural Visualization
Tridot
Rendering
Animation
Staff
Web Design
Design
Design Sub 1
Design Sub 2 (link)
Design Sub 3
Design Sub 2b
Production
Production Sub 1
HKS, Inc.
___________________________________________
My function is as follows
___________________________________________
<?php
function Tree($rootID, $database_jdt_cma, $jdt_cma)
{
mysql_select_db($database_jdt_cma, $jdt_cma);
$query_currentList = "SELECT page_id, page_title, page_parent_id, page_order FROM hks01_page WHERE page_parent_id = $rootID ORDER BY page_order ASC";
$currentList = mysql_query($query_currentList, $jdt_cma) or die(mysql_error());
$row_currentList = mysql_fetch_assoc($currentList);
$totalRows_currentList = mysql_num_rows($currentList);
do {
$parent_id = $row_currentList['page_id']; // set curent row to parent
echo( $row_currentList['page_title']."<br>\n" );
// find children of current row
$query_childList = "SELECT page_id, page_title, page_parent_id, page_order FROM hks01_page WHERE page_parent_id = $parent_id ORDER BY page_order ASC";
$childList = mysql_query($query_childList, $jdt_cma) or die(mysql_error());
$row_childList = mysql_fetch_assoc($childList);
$totalRows_childList = mysql_num_rows($childList);
if( $totalRows_childList != 0 ) {
// echo( " - Total Children: ".$totalRows_childList."<br>\n" );
return ( Tree($parent_id, $database_jdt_cma, $jdt_cma) );
}
} while ($row_currentList = mysql_fetch_assoc($currentList));
}
Tree(0, $database_jdt_cma, $jdt_cma);
?>
___________________________________________
and returns the following...
___________________________________________
Home
Contact Us
___________________________________________
No other records show.
If I comment out the return statement I get...
___________________________________________
Home
Architectural Visualization
Web Design
HKS, Inc.
___________________________________________
All top level, but obviously no children
If I leave in the return statement but rearrange the while statement as follows
___________________________________________
<?php
function Tree($rootID, $database_jdt_cma, $jdt_cma)
{
mysql_select_db($database_jdt_cma, $jdt_cma);
$query_currentList = "SELECT page_id, page_title, page_parent_id, page_order FROM hks01_page WHERE page_parent_id = $rootID ORDER BY page_order ASC";
$currentList = mysql_query($query_currentList, $jdt_cma) or die(mysql_error());
$row_currentList = mysql_fetch_assoc($currentList);
$totalRows_currentList = mysql_num_rows($currentList);
while ($row_currentList = mysql_fetch_assoc($currentList)) {
$parent_id = $row_currentList['page_id']; // set curent row to parent
echo( $row_currentList['page_title']."<br>\n" );
// find children of current row
$query_childList = "SELECT page_id, page_title, page_parent_id, page_order FROM hks01_page WHERE page_parent_id = $parent_id ORDER BY page_order ASC";
$childList = mysql_query($query_childList, $jdt_cma) or die(mysql_error());
$row_childList = mysql_fetch_assoc($childList);
$totalRows_childList = mysql_num_rows($childList);
if( $totalRows_childList != 0 ) {
//echo( " - Total Children: ".$totalRows_childList."<br>\n" );
return ( Tree($parent_id, $database_jdt_cma, $jdt_cma) );
}
}
}
Tree(0, $database_jdt_cma, $jdt_cma);
?>
___________________________________________
This gives me...
___________________________________________
Architectural Visualization
Rendering
Animation
Staff
___________________________________________
Skips the first record, gives the second record, all it's children, and then stops.
Somebody, please help me, I'm relatively new to PHP and have been mucking with this for days.
Thanks in advance for any help y'all can give me.
JD-

New Topic/Question
Reply



MultiQuote





|