Solved

PHP Dynamic Navigation

Posted on 2010-09-01
9
425 Views
Last Modified: 2012-06-27
Hi Experts. I am trying to create a 2 or 3 tiered php navigation system. I do not want to use 3rd party software and need the simplest method possible as I am still a beginner. I have managed to create one level or tier and am assuming I would simply need to add another variable to achieve my objective however nothing seems to be working. I have attached the code below. If anyone has any suggestions please let me know. Thanks!
<table width="70%">
<tr>

<td width="20%">
<b>2010 Permits & Invoices</b><br/>
<a href="index.php?page=year">year</a><br/>

<?php

	$page = $_GET['page'];
    	if ($page)
    {
    	include("inc/".$page.".php");
    }

?>

</td>

</tr>
</table>

Open in new window

0
Comment
Question by:brettsky07
[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
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 33582189
First question is what do you mean by "2 or 3 tiered php navigation system"?  Can you show us what you want it to look like and/or do?  Where is"$_GET['page']" coming from?
0
 
LVL 5

Expert Comment

by:drakeshe
ID: 33582330
what is inside page.php?
0
 
LVL 20

Expert Comment

by:virmaior
ID: 33582592
yeah, without knowing what is in page.php, there's really not much we can suggest...
if you really are going to have thousands of separate files, then your code would look something like the below.  

basically, you will want to use a delimiter to split the different segments. pick something that will never be one of the parameters.


usually you want to do pagination by using functions or objects so that you can have a single instance of code handle all the different pages for display and a second instance of code handle setting the parameter list.
<table width="70%">
<tr>

<td width="20%">
<b>2010 Permits & Invoices</b><br/>
<a href="index.php?page=year">year</a><br/>

<?php

        if (isset($_GET['param1']) and isset($_GET['param2'])) 
    {
	$page = $_GET['param1'] . '_' . $_GET['param2'];
    	include("inc/".$page.".php");
    }

?>

</td>

</tr>
</table>

Open in new window

0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

Author Comment

by:brettsky07
ID: 33587009
page.php simply contains links at this point.. no style or content... originally it had text content so when the 'year' link was clicked it displayed the contents of page.php. Now it is just holding links. However, if there is a way I could do this all from one page that would be extremely helpful...
0
 

Author Comment

by:brettsky07
ID: 33587156
What I am looking to achieve is a navigation hierarchy (vertical sidebar with links) where the user will click on "year" link and "month" links will appear. Than when the user clicks a month that months content will appear...

Ex. http://www.gomedia.us/contact/
- click on Work and "subnavigation" appears below... click on a sub link... that content is shown.
0
 

Author Comment

by:brettsky07
ID: 33587161
Note: just a basic version of this without the animation is what I am after.
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 33588410
That kind of menu is normally done in javascript since it needs to be executed in the browser.  PHP is used when the content of the second or third level needs to be looked up in a database.  Here's one source of menus: http://www.dynamicdrive.com/dynamicindex1/index.html
0
 
LVL 20

Expert Comment

by:virmaior
ID: 33588524
usually for this you would style a list:
<style type="text/css">
.menu_ul_label { font-weight:bold }
.menu_ul {

 display: block; padding: 0px; margin-left: 10px; list-style: none; 
}
.menu_ul li {
display: block; padding: 0px 0px; margin: 0px; list-style: none; 
} 
</style>

<ul class="menu_ul">
<li><div class="menu_ul_label">Part 1</div>
  <ul class="menu_ul">
    <li>link one</li>
    <li>link two</li>
   </ul>
</li>
<li><div class="menu_ul_label">Part 2</div>
  <ul class="menu_ul">
    <li>link three</li>
    <li>link four</li>
   </ul>
</li>
...
</li>

Open in new window

0
 

Author Closing Comment

by:brettsky07
ID: 33588821
Thanks. I think I will stick with the php I have and use an accordian style nav column for the rest.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

726 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