Solved

PHP MySQL tree menu

Posted on 2010-11-26
1
1,096 Views
Last Modified: 2012-05-10
Hi,
I'm trying to make my tree menu display properly but it's driving me a little bit nuts!

Basically I have the following code that produces a nested tree structure for pages in my cms:

 test.php

It is supposed to render as follows:

>Home
   - Spiders Attack!!!
      - About Page
   - Page Four Link
>HWRCs

but instead renders like this page (out of alignment)

http://dev.netbridge.co.uk/admin/test.php

I can of course supply css and extra code if it would help solve my problem, and I would really appreciate it if you could help in any way.

Thanks,

owennicol
0
Comment
Question by:owennicol
1 Comment
 
LVL 1

Accepted Solution

by:
leehanken earned 500 total points
ID: 34220208
The issue is in function build_child()

for ( $c=0;$c<$depth;$c++ )            // Indent over so that there is distinction between levels
{
$tempTree .= '<div class="test">';
}

Open in new window

which adds a div with a 20 pixel margin on the left depending on the depth, however the entire row is put within the div instead of just the left hand button.

To fix this you somehow need to just appy the margin to enclose this code
<span><a class="sexybutton sexysimple" href="edit_page.php?pid=' . $pid . '"><span class="book">' . $linklabel . '</span></a></span>

Open in new window


as shown below
function build_child($oldID)            // Recursive function to get all of the children...unlimited depth 
{ 
    global $exclude, $depth;            // Refer to the global array defined at the top of this script 
	include("../scripts/connect_to_mysql.php");
    $child_query = mysqli_query($myConnection,"SELECT pageorder, id, linklabel, pagetitle, showing, navigation, date_format(lastmodified,'%e/%c/%Y') as formattedDate FROM pages WHERE parent_id='$oldID' ORDER BY pageorder ASC" ); 
    while ( $child = mysqli_fetch_array($child_query, MYSQL_ASSOC) ) 
    {
		$pid = $child["id"];
		$linklabel = $child["linklabel"];
		$pagetitle = $child["pagetitle"];
		$pageorder = $child["pageorder"];
		$parent_id = $child["parent_id"];
		$showing = $child["showing"];
		$date = $child["formattedDate"];
		if($showing=='0'){ $show =  '<img src="../style/SexyButtons/images/icons/silk/cross.png" width="16" height="16" alt="cross" />';} else { $show = '<img 	src="../style/SexyButtons/images/icons/silk/tick.png" width="16" height="16" alt="tick" />';}
		$navigation = $child["navigation"];
		if($navigation=='0'){ $nav =  '<img src="../style/SexyButtons/images/icons/silk/cross.png" width="16" height="16" alt="cross" />';} else { $nav = '<img src="../style/SexyButtons/images/icons/silk/tick.png" width="16" height="16" alt="tick" />';}
        
		
		if ( $pid != $parent_id ) 
        { 	
			
			
				
			$tempTree .= '<li id="recordsArray_' . $pid . '"><span class="label">";

for ( $c=0;$c<$depth;$c++ )            // Indent over so that there is distinction between levels 
            { 	 			
				$tempTree .= '<span class="test">';  				 
			} 
$tempTree .= "<a class="sexybutton sexysimple" href="edit_page.php?pid=' . $pid . '"><span class="book">' . $linklabel . '</span></a></span></span>
	<span class="delete"><span style="padding-top:3px;"><a class="sexybutton sexysimple" onclick="confirmation()"><span class="cancel">Delete this page</span></a></span></form></span>
	<span class="nav" ><span style="padding-top:3px;">' . $nav . '</span></span>
		<span class="live" ><span style="padding-top:3px;">' . $show . '</span></span>
	<span class="order"><span style="padding-top:3px;">Drag</span></span>
	<span class="mod"><span style="padding-top:3px;">' . $date . '</span></span></li>';
			
            $depth++;        // Incriment depth b/c we're building this child's child tree  (complicated yet???) 
			$tempTree .= build_child($pid);        // Add to the temporary local tree 
			$depth--;        // Decrement depth b/c we're done building the child's child tree. 
            $tempTree .= '</div>';
			array_push($exclude, $pid);            // Add the item to the exclusion list 
			
        } 
    }  
   
    return $tempTree;        // Return the entire child tree 
}

Open in new window

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question