Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP MySQL tree menu

Posted on 2010-11-26
1
Medium Priority
?
1,111 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

916 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