Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP MySQL tree menu

Posted on 2010-11-26
1
Medium Priority
?
1,104 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
The viewer will learn how to count occurrences of each item in an array.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

722 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