Sub Navigation Bar Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dardsemail
Forum Contributor
Posts: 136
Joined: Thu Jun 03, 2004 9:02 pm

Sub Navigation Bar Question

Post by dardsemail »

Hi,

First let me say - I'm not a javascript person (and I'm barely a PHP person!) so you'll see my clear desire to avoid javascript in my code below.

Anyway, I'm working on a second level navigation menu that will only be shown based on the selection made by the user.

Here's my code:

Code: Select all

<?php
ob_start();
session_start();
?>
<table width="800px" align="center" height="140px" style="height:140px;" background="images/topnavlogo.gif">
	<tr>
		<td colspan="9">
		</td>
	</tr>
	<?php include ("loginbar.php");?>
</table>
<hr width="100%" color="#333333" size="1px">
<form action="<?=$_SERVER['PHP_SELF'];?>" method="POST" name="section"><table width="800px" align="center" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td align="center"><input name="section" type="hidden" value="collections"><img src="images/collections.gif" />
		</td>
		<td align="center"><a href="/aboutav.php" onClick="<?php showSubNav();?>"><input name="section" type="hidden" value="aboutus"><img src="images/aboutus.gif" border="0" /></a>
		</td>
		<td align="center"><input name="section" type="hidden" value="wellbeing"><img src="images/wellbeing.gif" />
		</td>
		<td align="center"><input name="section" type="hidden" value="press"><img src="images/press.gif" />
		</td>
		<td align="center"><input name="section" type="hidden" value="fashionconsultant"><img src="images/fashionconsultants.gif" />
		</td>
	</tr>
</table>
</form>
<?php
function showSubNav()
{
	$_SESSION['section']=$_POST['section'];
	
	if $_SESSION['section']='collections';
		{
		include ("collectionssubnav.php");
		}
		elseif $_SESSION['section']='aboutus';
		{
		include ("aboutussubnav.php");
		}
				elseif $_SESSION['section']='wellbeing';
		{
		include ("wellbeingssubnav.php");
		}
				elseif $_SESSION['section']='press';
		{
		include ("presssubnav.php");
		}
				elseif $_SESSION['section']='fashionconsultant';
		{
		include ("fashionconssubnav.php");
		}
				else
		{
		}
}
?>
When I load the page, nothing happens. This is my first attempt and trying to hand code anything like this, so please be gentle ;-)

Also, I'm open to any suggestions as to better methods for going about this type of procedure.

Thanks!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your function is a bit off..

Code: Select all

function showSubNav() 
{ 
      if( !empty($_POST['section']) )
        $_SESSION['section'] = $_POST['section']; 
    
      if( $_SESSION['section'] == 'collections' ) 
      { 
        include ("collectionssubnav.php"); 
      } 
      elseif( $_SESSION['section'] == 'aboutus')
      { 
        include ("aboutussubnav.php"); 
      } 
      elseif( $_SESSION['section'] == 'wellbeing')
      { 
        include ("wellbeingssubnav.php"); 
      } 
      elseif( $_SESSION['section'] == 'press' ) 
      { 
        include ("presssubnav.php"); 
      } 
      elseif( $_SESSION['section'] == 'fashionconsultant' )
      { 
        include ("fashionconssubnav.php"); 
      } 
}
however, I'd suggest going to a switch

Code: Select all

function showSubNav() 
{ 
      if( !empty($_POST['section']) )
        $_SESSION['section'] = $_POST['section']; 

    switch($_SESSION['section'])
    {
      case 'collections':
        include ("collectionssubnav.php"); 
        break;

      case 'aboutus':
        include ("aboutussubnav.php"); 
        break;

      case 'wellbeing':
        include ("wellbeingssubnav.php"); 
        break;

      case 'press': 
        include ("presssubnav.php"); 
        break;

      case 'fashionconsultant':
        include ("fashionconssubnav.php"); 
        break;
    }
}
dardsemail
Forum Contributor
Posts: 136
Joined: Thu Jun 03, 2004 9:02 pm

Post by dardsemail »

Thanks Feyd! I changed it to the switch version and was still getting a blank screen.

I decided to do some changing around of the code because I thought that perhaps there was a problem with the fact that the code was calling a function that wasn't defined until later in the document. But, still, a blank screen.

I feel like I'm on the right track, but perhaps a little skewed in my abilities... here's my code:

Code: Select all

<?php
session_start();
$_SESSION['section'] = 'home';

function showSubNav() 
{ 
       if( !empty($_POST['section']) ) 
        $_SESSION['section'] = $_POST['section']; 

     switch($_SESSION['section']) 
    { 
      case 'collections': 
         showCollectionsSubNav(); 
         break; 

      case 'aboutus': 
		showAboutUsSubNav();
         break; 

      case 'wellbeing': 
        include ("wellbeingssubnav.php"); 
         break; 

      case 'press': 
         include ("presssubnav.php"); 
         break; 

      case 'fashionconsultant': 
        include ("fashionconssubnav.php"); 
         break; 
    } 
}
?>
<table width="800px" align="center" height="140px" style="height:140px;" background="images/topnavlogo.gif">
	<tr>
		<td colspan="9">
		</td>
	</tr>
	<?php include ("loginbar.php");?>
</table>
<hr width="100%" color="#333333" size="1px">
<form action="<?=$_SERVER['PHP_SELF'];?>" method="POST" name="section"><table width="800px" align="center" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td align="center"><input name="section" type="hidden" value="collections"><img src="images/collections.gif" />
		</td>
		<td align="center"><a href="/aboutav.php" onClick="<?php showSubNav();?>"><input name="section" type="hidden" value="aboutus"><img src="images/aboutus.gif" border="0" /></a>
		</td>
		<td align="center"><input name="section" type="hidden" value="wellbeing"><img src="images/wellbeing.gif" />
		</td>
		<td align="center"><input name="section" type="hidden" value="press"><img src="images/press.gif" />
		</td>
		<td align="center"><input name="section" type="hidden" value="fashionconsultant"><img src="images/fashionconsultants.gif" />
		</td>
	</tr>
</table>
</form>
<?php

function showCollectionsSubNav()
{
	include ("collectionssubnav.phpp");
	}
	
function showAboutUsSubNav()
{
	include ("aboutussubnav.php"); 
	}	
	         

?>
dardsemail
Forum Contributor
Posts: 136
Joined: Thu Jun 03, 2004 9:02 pm

Post by dardsemail »

I think I'm going to have to use Javascript somehow... can anyone tell me how I would set the value of $_POST['section'] to be the value of the link clicked?

I'm drawing a complete blank!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

<a href="/aboutav.php<?php if( !empty($_POST&#1111;'section']) ) &#123; $_SESSION&#1111;'section'] = $_POST&#1111;'section']; &#125; echo (!empty($_SESSION&#1111;'section']) ? '?section='.$_SESSION&#1111;'section'] : '' ) ?>">
dardsemail
Forum Contributor
Posts: 136
Joined: Thu Jun 03, 2004 9:02 pm

Post by dardsemail »

Thanks Feyd - I've messed with my code so much, I'm not even sure where I'd put it now...

Still a blank page!!! Besides being an idiot - where am I going wrong? I know that this shouldn't be this hard!

I'm about to pull my hair out 8O

Code: Select all

<?php
session_start();

if ($_POST['section'])
	{
	$_SESSION['section']=$_POST['section'];
	showSubNav();
	}
	else
	{
	exit;
	}

?>
<table width="800px" align="center" height="140px" style="height:140px;" background="images/topnavlogo.gif">
	<tr>
		<td colspan="9">
		</td>
	</tr>
	<?php include ("loginbar.php");?>
</table>
<hr width="100%" color="#333333" size="1px">
<form action="<?=$_SERVER['PHP_SELF'];?>" name="frm_section" method="post"><table width="800px" align="center" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td align="center"><img src="images/collections.gif" />
		</td>
		<td align="center"><a href="aboutav.php"><input name="section" type="hidden" value="aboutus"><img src="images/aboutus.gif" border="0" /></a>
		</td>
		<td align="center"><img src="images/wellbeing.gif" />
		</td>
		<td align="center"><img src="images/press.gif" />
		</td>
		<td align="center"><img src="images/fashionconsultants.gif" />
		</td>
	</tr>
</table>
</form>
<?php
function showSubNav() 
{ 
     switch($_SESSION['section']) 
    { 
      case 'collections': 
         include ("collectionssubnav.php"); 
         break; 

      case 'aboutus': 
		 include ("aboutussubnav.php"); 
         break; 

      case 'wellbeing': 
        include ("wellbeingssubnav.php"); 
         break; 

      case 'press': 
         include ("presssubnav.php"); 
         break; 

      case 'fashionconsultant': 
        include ("fashionconssubnav.php"); 
         break; 
    } 
}

?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you may have a parse error or something.. your page should print, at the least, the html outside of php (unless there is an error of some sort)

check your error logs..
dardsemail
Forum Contributor
Posts: 136
Joined: Thu Jun 03, 2004 9:02 pm

Post by dardsemail »

I think I'm going to post a new topic because I seem to have been able to work around this somehow, but just have a quick question regarding how to set a session when using a hyperlink.

Thanks for your help Feyd!
Post Reply