Navigation Problem

Not same as before

  • (2 Pages)
  • +
  • 1
  • 2

27 Replies - 2320 Views - Last Post: 01 January 2011 - 01:24 PM Rate Topic: -----

#1 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Navigation Problem

Posted 31 December 2010 - 07:38 PM

Hello, it appears that I'm having another navigation problem. My cousin tried to help me with it and was unable to help. This is for a forum that I'm creating, C0dingF0x. Here is an image of the problem:
Attached Image
Here is what the navigation is supposed to look like:
Attached Image
I'm not really sure why it's doing this. It even does it when you go to create a topic. Here is the whole code for index.php (Where the problem is):
<?php

session_start();
include_once "scripts/connection.php";

$action = $_GET['act'];
$actions_array = array('forum', 'create');

?>
<!DOCTYPE html>
<html lang="en">
	<head>
	<meta charset="utf-8" />
	<meta name="Description" content="Welcome to C0dingF0x by Env X Software.  C0dingF0x is a forum where you can ask questions about anything and chat with friends!" />
	<meta name="Keywords" content="coding,fox,c0ding,f0x,c0dingf0x,codingfox,home,forum,env,x,software" />
	<meta name="rating" content="General" />
	<title>C0dingF0x</title>
	<link href="style/default.css" rel="stylesheet" type="text/css" />
	<link href="style/search.css" rel="stylesheet" type="text/css" />
	<link href="style/forum_content.css" rel="stylesheet" type="text/css" />
	<link href="style/forum.css" rel="stylesheet" type="text/css" />
	
	<!--[if IE]>
		<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
	<!--[if lte IE 7]>
		<script src="js/IE8.js" type text/javascript"></script><![endif]-->
	</head>
	<body>
			<header>
				<form class="searchform">
					<input class="searchfield" type="text" value="Search..." onfocus="if (this.value == 'Search...') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Search...';}" />
					<input class="searchbutton" type="submit" value="Go" />
				</form>
			</header>
			<nav>
				<ul class="menu">
					<li class="title"><a id="1" href="#1"><span>Main</span></a>
				<ul>
					<li><a href="index.php">Home</a></li>
					<li><a href="about.php">About</a></li>
					<li><a href="login.php">Login</a></li>
					<li><a href="register.php">Register</a></li>
				</ul>
					</li>
				<?php
					if($_SESSION['username'])
					{
						echo "<li class='title'><a id='2' href='#2'><span>Profile</span></a>";
						echo "<ul>";
							$sql = "SELECT * FROM `users` WHERE `username`='".$_SESSION['username']."'";
							$res = mysql_query($sql) or die(mysql_error());
							$row = mysql_fetch_assoc($res);
						if($row['admin'] == '1')
						{
							echo "<li><a href='admin.php'>Admin</a></li>";
						}
						echo "<li><a href='profile.php'>View Profile</a></li>";
						echo "<li><a href='#'>Edit Profile</a></li>";
						echo "<li><a href='scripts/logout.php'>Logout</a></li>";
						echo "</ul>";
						echo "</li>";
					}
				$admin_user_level = $row['admin'];
				if(!in_array($action, $actions_array))
				{
					$sql1 = "SELECT * FROM `forum_cats` WHERE `admin` < ".$row['admin']."+1";
					$res1 = mysql_query($sql1) or die(mysql_error());
					
					while($row2 = mysql_fetch_assoc($res1))
					{
						if($row2['name'] == "Programming and Web Development Help")
						
						echo " <li class=\"title\"><a id=\"3\" href=\"#3\"><span>".$row2['name']."</span></a>";
						
						if($row2['name'] == "Programming and Web Development Tutorials")
						
						echo " <li class=\"title\"><a id=\"4\" href=\"#4\"><span>".$row2['name']."</span></a>";
						
						if($row2['name'] == "Homework Help")
						
						echo " <li class=\"title\"><a id=\"5\" href=\"#5\"><span>".$row2['name']."</span></a>";
						
						if($row2['name'] == "Moderation")
						
						echo " <li class=\"title\"><a id=\"6\" href=\"#6\"><span>".$row2['name']."</span></a>";
						
						$sql2 = "SELECT * FROM `forum_sub_cats` WHERE `cid`='".$row2['id']."' AND `admin` < ".$row['admin']."+1";
						$res2 = mysql_query($sql2) or die(mysql_error());
						echo " <ul>";
						
						while($row3 = mysql_fetch_assoc($res2))
						{
						echo " <li><a href=\"./index.php?act=forum&id=".$row2['id']."&".$row3['id']."\" id=\"link" . $row3['id'] . "\">".$row3['name']."</a></li>";

						
					}
						echo " </ul>";
						
						}
						echo "</li>";
				}
				?>
					<li id="bottom"><p>C0dingF0x</p><ul></ul></li>
				</ul>
			</nav>
			<div class="index_content">
				<?php
				$admin_user_level = $row['admin'];
				if(!in_array($action, $actions_array))
				{
					$sql1 = "SELECT * FROM `forum_cats` WHERE `admin` < ".$row['admin']."+1";
					$res1 = mysql_query($sql1) or die(mysql_error());
					
					while($row2 = mysql_fetch_assoc($res1))
					{
						echo "<div id=\"forum_content\">";
						echo " <div id=\"forum_header\"><p class=\"name\">".$row2['name']."</p></div>";
						
						$sql2 = "SELECT * FROM `forum_sub_cats` WHERE `cid`='".$row2['id']."' AND `admin` < ".$row['admin']."+1";
						$res2 = mysql_query($sql2) or die(mysql_error());
						
						while($row3 = mysql_fetch_assoc($res2))
						{
						echo " <div id=\"content\">";
						echo " <a href=\"./index.php?act=forum&id=".$row2['id']."&".$row3['id']."\" id=\"link\"" . $row3['id'] . "\">".$row3['name']."</a>";
						echo " </div>";
						}
						echo "</div>";
					}
				}else{
					if($action == 'forum')
					{
						echo " <div id=\"forum_topics\">";
						include "scripts/forum.php";
						echo " </div>";
					}
					if($action == 'create')
					{
						include "scripts/create.php";
					}
				}
				?>
			</div>
			<footer>Copyright &#169 <a href="http://www.envxsoftware.com/">Env X Software</a></footer>
	</body>
</html>

Here is forum.php:
<?php

$id = strip_tags($_GET['id']);

if($id)
{
	$sql = "SELECT * FROM `forum_sub_cats` WHERE `id`='".$id."'";
	$res = mysql_query($sql) or die(mysql_error());
	
	if(mysql_num_rows($res) == 0)
	{
		echo "<p class=\"error\">That forum category does not exist!</p>";
	}else{
		$row = mysql_fetch_assoc($res);
		if($row['admin'] == 1 && $admin_user_level == 0)
		{
			echo "<p class=\"error\">You must be an administrator to view this forum!</p>";
		}else{
			$sql2 = "SELECT * FROM `topics` WHERE `cid`='".$row['id']."'";
			$res2 = mysql_query($sql2) or die(mysql_error);
			
			if(mysql_num_rows($res2) == 0)
			{
				echo "<p class=\"error\">There are no topics in this forum, <a href=\"index.php?act=create&id=".$row['id']."\"id=\"link\">Create Topic</a>!</p>";
			}
		}
	}
}
?>

Here is create.php
<?php

$id = $_GET['id'];
$cid = $_GET['cid'];


if($id)
{
	$sql = "SELECT * FROM `forum_sub_cats` WHERE  `id`='".$id."'";
	$res = mysql_query($sql) or die(mysql_error());
	
	if(mysql_num_rows($res) == 0)
	{
		echo "<p class=\"error\">The forum you're trying to post this topic in doesn't exist!</p>";
	}else{
				$fcname = mysql_query("SELECT `name` FROM `forum_cats` WHERE `id`='".$cid."'");
				
					echo "<div id=\"container1\">";
						echo $fcname." -> ".$fname;
						echo "<p class=\"finfo\">Information</p>";
						echo "<form id=\"create_topic\" method=\"post\" action=\"index.php?act=create\">";
						echo "<div class=\"finput\">";
						echo "<input type=\"text\" name=\"title\" style=\"padding: 9px; border: solid 1px #E5E5E5; outline: 0; font: normal 13px/100% Verdana, Tahoma, sans-serif; width: 200px; 
						background: -webkit-gradient(linear, left top, left 25, from(#FFFFFF), color-stop(4%, #EEEEEE), to(#FFFFFF)); background: -moz-linear-gradient(top, #FFFFFF, #EEEEEE 1px, #FFFFFF 25px); box-shadow: rgba(0,0,0, 0.1) 0px 0px 8px;
						-moz-box-shadow: rgba(0,0,0, 0.2) 0px 0px 8px; -webkit-box-shadow: rgba(0,0,0, 0.2) 0px 0px 8px; -moz-border-radius: 10px; -webkit-border-radius: 10px; border: 1px solid #000;\"/><label for=\"title\"> Title</label><br />";
						echo "</div>";
						echo "<input type=\"text\" name=\"desc\" style=\"padding: 9px; border: solid 1px #E5E5E5; outline: 0; font: normal 13px/100% Verdana, Tahoma, sans-serif; width: 200px; 
						background: -webkit-gradient(linear, left top, left 25, from(#FFFFFF), color-stop(4%, #EEEEEE), to(#FFFFFF)); background: -moz-linear-gradient(top, #FFFFFF, #EEEEEE 1px, #FFFFFF 25px); box-shadow: rgba(0,0,0, 0.1) 0px 0px 8px;
						-moz-box-shadow: rgba(0,0,0, 0.2) 0px 0px 8px; -webkit-box-shadow: rgba(0,0,0, 0.2) 0px 0px 8px; -moz-border-radius: 10px; -webkit-border-radius: 10px; border: 1px solid #000;\"/><label for=\"desc\"> Description</label><br />";
						echo "<p class=\"finfo\">Topic</p>";
						echo "<textarea name=\"topic_message\" rows=\"10\" cols=\"73\" style=\"padding: 9px; border: solid 1px #E5E5E5; outline: 0; font: normal 13px/100% Verdana, Tahoma, sans-serif; width: 200px; 
						background: -webkit-gradient(linear, left top, left 25, from(#FFFFFF), color-stop(4%, #EEEEEE), to(#FFFFFF)); background: -moz-linear-gradient(top, #FFFFFF, #EEEEEE 1px, #FFFFFF 25px); box-shadow: rgba(0,0,0, 0.1) 0px 0px 8px;
						-moz-box-shadow: rgba(0,0,0, 0.2) 0px 0px 8px; -webkit-box-shadow: rgba(0,0,0, 0.2) 0px 0px 8px; -moz-border-radius: 10px; -webkit-border-radius: 10px; border: 1px solid #000; width: 97%;\" ></textarea>";
						echo "<div class=\"fpost\">";
						echo "<input type=\"submit\" name=\"Post\" value=\"Post Topic\" style=\"width: auto; padding: 9px 15px; background: #800000; border: 0; font-size: 14px; color: #FFFFFF; border-radius: 25px; border: 1px solid #000; cursor: pointer; \" />";
						echo "</div>";
					echo "</div>";
			
	}
}

?>

Please do note that create.php is messed up as I'm trying to get the form to display on top what the category and sub category are(if you do want to help with that too I would appreciate it). Thanks in advance guys!

Is This A Good Question/Topic? 0
  • +

Replies To: Navigation Problem

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2896
  • View blog
  • Posts: 10,036
  • Joined: 08-August 08

Re: Navigation Problem

Posted 31 December 2010 - 09:16 PM

Mixing html, php, javascript, and even some css together in the same file is asking for trouble in exactly the form you're having. You really should separate them if you want to be able to manage your code.
Was This Post Helpful? 0
  • +
  • -

#3 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Re: Navigation Problem

Posted 31 December 2010 - 09:36 PM

View PostCTphpnwb, on 31 December 2010 - 10:16 PM, said:

Mixing html, php, javascript, and even some css together in the same file is asking for trouble in exactly the form you're having. You really should separate them if you want to be able to manage your code.

I'm going to put the nav, footer, and header in separate files. I'm not sure if I should use include, include_once, require, or require_once. Which one should I use.
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2896
  • View blog
  • Posts: 10,036
  • Joined: 08-August 08

Re: Navigation Problem

Posted 31 December 2010 - 09:49 PM

I'd use require_once or require. At this point it doesn't really matter so long as you get them separated enough so that you can follow your own logic. I know I'm too tired to follow it the way it is now.
Was This Post Helpful? 0
  • +
  • -

#5 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Re: Navigation Problem

Posted 31 December 2010 - 10:34 PM

View PostCTphpnwb, on 31 December 2010 - 10:49 PM, said:

I'd use require_once or require. At this point it doesn't really matter so long as you get them separated enough so that you can follow your own logic. I know I'm too tired to follow it the way it is now.

Okay. When I'm done with that I'll post the code on here. I'll add comments.

This post has been edited by EnvXOwner: 01 January 2011 - 01:26 AM

Was This Post Helpful? 0
  • +
  • -

#6 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Re: Navigation Problem

Posted 01 January 2011 - 01:26 AM

Here is my new code for index.php:
<?php

session_start();
require_once "scripts/connection.php";

$action = $_GET['act'];
$actions_array = array('forum', 'create');

?>
<!DOCTYPE html>
<html lang="en">
	<head>
	<meta charset="utf-8" />
	<meta name="Description" content="Welcome to C0dingF0x by Env X Software.  C0dingF0x is a forum where you can ask questions about anything and chat with friends!" />
	<meta name="Keywords" content="coding,fox,c0ding,f0x,c0dingf0x,codingfox,home,forum,env,x,software" />
	<meta name="rating" content="General" />
	<title>C0dingF0x | Forum Index</title>
	<link href="style/default.css" rel="stylesheet" type="text/css" />
	<link href="style/search.css" rel="stylesheet" type="text/css" />
	<link href="style/forum_content.css" rel="stylesheet" type="text/css" />
	<link href="style/forum.css" rel="stylesheet" type="text/css" />
	
	<!--[if IE]>
		<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
	<!--[if lte IE 7]>
		<script src="js/IE8.js" type=text/javascript"></script><![endif]-->
	</head>
	<body>
			<header>
				<!-- Header file -->
				<?php include('includes/header.php');?>
				<!-- /Header file -->
			</header>
			<nav>
				<!-- Navigation file -->
				<?php include('includes/nav.php');?>
				<!-- /Navigation file -->
			</nav>
			<div class="index_content">
				<!-- Forum categories and subcategories -->
				<?php include('includes/index_content.php');?>
				<!-- /Forum categories and subcategories -->
			</div>
			<footer>
				<!-- Footer -->
				<?php include('includes/footer.php');?>
				<!--/Footer -->
			</footer>
	</body>
</html>

Here is nav.php:
<ul class="menu">
	<li class="title"><a id="1" href="#1"><span>Main</span></a>
		<ul>
			<li><a href="index.php">Home</a></li>
			<li><a href="about.php">About</a></li>
			<li><a href="login.php">Login</a></li>
			<li><a href="register.php">Register</a></li>
		</ul>
	</li>
	<?php
		if($_SESSION['username'])
		{
			echo "<li class='title'><a id='2' href='#2'><span>Profile</span></a>";
			echo "<ul>";
			
			$sql = "SELECT * FROM `users` WHERE `username`='".$_SESSION['username']."'";
			$res = mysql_query($sql) or die(mysql_error());
			$row = mysql_fetch_assoc($res);
			if($row['admin'] == '1')
			{
				echo "<li><a href='admin.php'>Admin</a></li>";
			}
			echo "<li><a href='profile.php'>View Profile</a></li>";
			echo "<li><a href='#'>Edit Profile</a></li>";
			echo "<li><a href='scripts/logout.php'>Logout</a></li>";
			echo "</ul>";
			echo "</li>";
		}
		$admin_user_level = $row['admin'];
		if(!in_array($action, $actions_array))
		{
			$sql1 = "SELECT * FROM `forum_cats` WHERE `admin` < ".$row['admin']."+1";
			$res1 = mysql_query($sql1) or die(mysql_error());
					
			while($row2 = mysql_fetch_assoc($res1))
			{
				if($row2['name'] == "Programming and Web Development Help")
						
				echo " <li class=\"title\"><a id=\"3\" href=\"#3\"><span>".$row2['name']."</span></a>";
						
				if($row2['name'] == "Programming and Web Development Tutorials")
						
				echo " <li class=\"title\"><a id=\"4\" href=\"#4\"><span>".$row2['name']."</span></a>";
						
				if($row2['name'] == "Homework Help")
						
				echo " <li class=\"title\"><a id=\"5\" href=\"#5\"><span>".$row2['name']."</span></a>";
						
				if($row2['name'] == "Moderation")
						
				echo " <li class=\"title\"><a id=\"6\" href=\"#6\"><span>".$row2['name']."</span></a>";
						
				$sql2 = "SELECT * FROM `forum_sub_cats` WHERE `cid`='".$row2['id']."' AND `admin` < ".$row['admin']."+1";
				$res2 = mysql_query($sql2) or die(mysql_error());
				echo " <ul>";
						
			while($row3 = mysql_fetch_assoc($res2))
			{
				echo "<li><a id=\"link\" href=\"./index.php?act=forum&id=".$row2['id']."&".$row3['id']."\">".$row3['name']."</a></li>";
			}
				echo " </ul>";
			}
				echo "</li>";
		}
	?>
	<li id="bottom"><p>C0dingF0x</p><ul></ul></li>
</ul>

Here is index_content.php:
<?php
$admin_user_level = $row['admin'];
	if(!in_array($action, $actions_array))
		{
			$sql1 = "SELECT * FROM `forum_cats` WHERE `admin` < ".$row['admin']."+1";
			$res1 = mysql_query($sql1) or die(mysql_error());
						
			while($row2 = mysql_fetch_assoc($res1))
			{
				echo "<div id=\"forum_content\">";
				echo " <div id=\"forum_header\"><p class=\"name\">".$row2['name']."</p></div>";
							
				$sql2 = "SELECT * FROM `forum_sub_cats` WHERE `cid`='".$row2['id']."' AND `admin` < ".$row['admin']."+1";
				$res2 = mysql_query($sql2) or die(mysql_error());
							
				while($row3 = mysql_fetch_assoc($res2))
				{
					echo " <div id=\"content\">";
					echo " <a id=\"link\" href=\"./index.php?act=forum&id=".$row3['id']."&".$row2['id']."\">".$row3['name']."</a>";
					echo " </div>";
				}
					echo "</div>";
			}
		}else{
			if($action == 'forum')
			{
				echo " <div id=\"forum_topics\">";
				include "scripts/forum.php";
				echo " </div>";
			}
				if($action == 'create')
				{
					include "scripts/create.php";
				}
			}
?>

Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,441
  • Joined: 23-August 08

Re: Navigation Problem

Posted 01 January 2011 - 06:30 AM

So is there still a problem?

This code here:
				if($row2['name'] == "Programming and Web Development Help")
						
				echo " <li class=\"title\"><a id=\"3\" href=\"#3\"><span>".$row2['name']."</span></a>";
						
				if($row2['name'] == "Programming and Web Development Tutorials")
						
				echo " <li class=\"title\"><a id=\"4\" href=\"#4\"><span>".$row2['name']."</span></a>";
						
				if($row2['name'] == "Homework Help")
						
				echo " <li class=\"title\"><a id=\"5\" href=\"#5\"><span>".$row2['name']."</span></a>";
						
				if($row2['name'] == "Moderation")
						
				echo " <li class=\"title\"><a id=\"6\" href=\"#6\"><span>".$row2['name']."</span></a>";



doesn't that look a little repetitive to you? It should.
Was This Post Helpful? 0
  • +
  • -

#8 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2896
  • View blog
  • Posts: 10,036
  • Joined: 08-August 08

Re: Navigation Problem

Posted 01 January 2011 - 07:17 AM

You still need to break it up more. This is only a start towards making it readable. I haven't made any changes to your logic or reduced any repetitive code:

index.php
<?php
session_start();
require_once "scripts/connection.php";

$action = $_GET['act'];
$actions_array = array('forum', 'create');

$output = file_get_contents("main.html");
$replace = array("PHPHEADER", "PHPNAVIGATION", "PHPCONTENT", "PHPFOOTER");
$with = array();
include('includes/header.php');
$with[] = $header_output;
include('includes/nav.php');
$with[] = $nav_output;
include('includes/index_content.php');
$with[] = $content_output;
include('includes/footer.php');
$with[] = $footer_output;

$output = str_replace($replace, $with, $output);

echo $output;
?>


main.html
<!DOCTYPE html>
<html lang="en">
	<head>
	<meta charset="utf-8" />
	<meta name="Description" content="Welcome to C0dingF0x by Env X Software.  C0dingF0x is a forum where you can ask questions about anything and chat with friends!" />
	<meta name="Keywords" content="coding,fox,c0ding,f0x,c0dingf0x,codingfox,home,forum,env,x,software" />
	<meta name="rating" content="General" />
	<title>C0dingF0x | Forum Index</title>
	<link href="style/default.css" rel="stylesheet" type="text/css" />
	<link href="style/search.css" rel="stylesheet" type="text/css" />
	<link href="style/forum_content.css" rel="stylesheet" type="text/css" />
	<link href="style/forum.css" rel="stylesheet" type="text/css" />
	
	<!--[if IE]>
		<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
	<!--[if lte IE 7]>
		<script src="js/IE8.js" type=text/javascript"></script><![endif]-->
	</head>
	<body>
			<header>
				PHPHEADER
			</header>
			<nav>
				PHPNAVIGATION
				</nav>
			<div class="index_content">
				PHPCONTENT
			</div>
			<footer>
				PHPFOOTER
			</footer>
	</body>
</html>

nav.php
<?php
$nav_output = file_get_contents("nav.html");
if($_SESSION['username'])
{
	$nav_output .= "<li class='title'><a id='2' href='#2'><span>Profile</span></a>";
	$nav_output .= "<ul>";
	
	$sql = "SELECT * FROM `users` WHERE `username`='".$_SESSION['username']."'";
	$res = mysql_query($sql) or die(mysql_error());
	$row = mysql_fetch_assoc($res);
	if($row['admin'] == '1')
	{
	$nav_output .= "<li><a href='admin.php'>Admin</a></li>";
	}
	$nav_output .= "<li><a href='profile.php'>View Profile</a></li>";
	$nav_output .= "<li><a href='#'>Edit Profile</a></li>";
	$nav_output .= "<li><a href='scripts/logout.php'>Logout</a></li>";
	$nav_output .= "</ul>";
	$nav_output .= "</li>";
}
$admin_user_level = $row['admin'];
if(!in_array($action, $actions_array))
{
	$sql1 = "SELECT * FROM `forum_cats` WHERE `admin` < ".$row['admin']."+1";
	$res1 = mysql_query($sql1) or die(mysql_error());
		
	while($row2 = mysql_fetch_assoc($res1))
	{
		if($row2['name'] == "Programming and Web Development Help")
			$nav_output .= " <li class=\"title\"><a id=\"3\" href=\"#3\"><span>".$row2['name']."</span></a>";
		
		if($row2['name'] == "Programming and Web Development Tutorials")
			$nav_output .= " <li class=\"title\"><a id=\"4\" href=\"#4\"><span>".$row2['name']."</span></a>";
		
		if($row2['name'] == "Homework Help")
			$nav_output .= " <li class=\"title\"><a id=\"5\" href=\"#5\"><span>".$row2['name']."</span></a>";
		
		if($row2['name'] == "Moderation")
			$nav_output .= " <li class=\"title\"><a id=\"6\" href=\"#6\"><span>".$row2['name']."</span></a>";
		
		$sql2 = "SELECT * FROM `forum_sub_cats` WHERE `cid`='".$row2['id']."' AND `admin` < ".$row['admin']."+1";
		$res2 = mysql_query($sql2) or die(mysql_error());
		$nav_output .= " <ul>";
		
		while($row3 = mysql_fetch_assoc($res2))
		{
			$nav_output .= "<li><a id=\"link\" href=\"./index.php?act=forum&id=".$row2['id']."&".$row3['id']."\">".$row3['name']."</a></li>";
		}
		$nav_output .= " </ul>";
	}
	$nav_output .= "</li>";
}
$nav_output .= '<li id="bottom"><p>C0dingF0x</p><ul></ul></li>
</ul>';

nav.html
<ul class="menu">
	<li class="title"><a id="1" href="#1"><span>Main</span></a>
		<ul>
			<li><a href="index.php">Home</a></li>
			<li><a href="about.php">About</a></li>
			<li><a href="login.php">Login</a></li>
			<li><a href="register.php">Register</a></li>
		</ul>
	</li>



It's not complete and it's untested, but hopefully you can see how the logic is much easier to see in each of the files because the languages are separated. If you were to incorporate Jack's recommendation it would be even clearer.

This post has been edited by CTphpnwb: 01 January 2011 - 07:19 AM

Was This Post Helpful? 1
  • +
  • -

#9 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,441
  • Joined: 23-August 08

Re: Navigation Problem

Posted 01 January 2011 - 08:48 AM

A refactored nav.php (untested, again)

<?php

function getNavAnchorLinkItem($class, $id, $text, $terminate=TRUE)
{
    return "<li class='$class'><a id='$id' href='#$id'><span>$text</span></a>" . ($terminate ? "</li>" : "");
}

function getUniversalNavLinks(&$id)
{
    // FALSE to leave off </li>
    $nav_output = getNavAnchorLinkItem('title', $id++, 'Profile', FALSE);
    $nav_output .= "<ul>";
    $sql = "SELECT admin FROM `users` WHERE `username`='".$_SESSION['username']."'";
    $res = mysql_query($sql) or die(mysql_error());
    $row = mysql_fetch_assoc($res);
    if($row['admin'] == '1')
    {
        $nav_output .= "<li><a href='admin.php'>Admin</a></li>";
    }
    $nav_output .= "<li><a href='profile.php'>View Profile</a></li>";
    $nav_output .= "<li><a href='#'>Edit Profile</a></li>";
    $nav_output .= "<li><a href='scripts/logout.php'>Logout</a></li>";
    $nav_output .= "</ul>";
    $nav_output .= "</li>";

    return $nav_output;
}

function getSubCatNav($admin_user_level, $forumID)
{
    $nav_output	= "";
    $sql = "SELECT id, name FROM `forum_sub_cats` WHERE `cid`='$forumID' AND `admin` < $admin_user_level+1";
    $res = mysql_query($sql) or die(mysql_error());
    $nav_output .= " <ul>";

    while($row = mysql_fetch_assoc($res))
    {
        $nav_output .= "<li><a id=\"link\" href=\"./index.php?act=forum&id=$forumID&" . $row['id'] . "\">" . $row['name'] . "</a></li>";
    }
    $nav_output .= " </ul>";

    return $nav_output;
}

function getNav($admin_user_level, &$id)
{
    $nav_output = "";
    $sql = "SELECT id, name FROM `forum_cats` WHERE `admin` < $admin_user_level+1";
    $res = mysql_query($sql) or die(mysql_error());

    while($row = mysql_fetch_assoc($res))
    {
        $nav_output .= getNavAnchorLinkItem('title', $id++, $row['name']);
        $nav_output .= getSubCatNav($admin_user_level, $row['id']);
    }
    $nav_output .= "</li>";
    return $nav_output;
}

$nav_output = file_get_contents("nav.html");
$id = 2;
if(isset($_SESSION['username']) && !empty($_SESSION['username']))
{
    $nav_output .= getUniversalNavLinks($nav_output, $id);
}

$admin_user_level = $row['admin'];
if(!in_array($action, $actions_array))
{
    $nav_output .= getNav($admin_user_level, $id);
}
$nav_output .= '</li>'; // Close li opened in getUniversalNavLinks
$nav_output .= '<li id="bottom"><p>C0dingF0x</p><ul></ul></li></ul>';


This post has been edited by JackOfAllTrades: 01 January 2011 - 12:40 PM
Reason for edit:: Fixed problems in getNav pointed out later in the topic.

Was This Post Helpful? 1
  • +
  • -

#10 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Re: Navigation Problem

Posted 01 January 2011 - 09:24 AM

I still get the same problem when I click on a subcategory and a subcategory that I did in the image. Now my header and navigation are on the bottom of the page after index_content. I've tried yours JackOfAllTrades and it seems to basically the same except that the navigation on the index page only shows Main and if you're loggged in Profile. I like how you guys clean the code. I never knew that you can separate code like that. Are you basically saying that I shouldn't mix HTML with PHP? I notice on the navigation that's what you guys seem to be leaning to. If I can get this to work, understand it then I will use it on all of my pages and on other websites that I may make.
Was This Post Helpful? 0
  • +
  • -

#11 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2896
  • View blog
  • Posts: 10,036
  • Joined: 08-August 08

Re: Navigation Problem

Posted 01 January 2011 - 10:02 AM

Would you write a paper in English and insert random sentences/words in Spanish? Do you think that would be a pleasant reading experience?

The point of separating code is to make it easier to read. If it's easy to read then it will be much easier to find and solve problems. I haven't even begun to look for your original problem yet because that would still be too much work. Let's make it readable first.
Was This Post Helpful? 0
  • +
  • -

#12 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Re: Navigation Problem

Posted 01 January 2011 - 10:06 AM

View PostCTphpnwb, on 01 January 2011 - 11:02 AM, said:

Would you write a paper in English and insert random sentences/words in Spanish? Do you think that would be a pleasant reading experience?

The point of separating code is to make it easier to read. If it's easy to read then it will be much easier to find and solve problems. I haven't even begun to look for your original problem yet because that would still be too much work. Let's make it readable first.

I understand. This will make easier for me and others when I end up with a couple hundred lines of code. I do appreciate you guys helping me clean up my code. In the process I'm learning how more things.
Was This Post Helpful? 0
  • +
  • -

#13 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,441
  • Joined: 23-August 08

Re: Navigation Problem

Posted 01 January 2011 - 10:07 AM

Why don't you explain your logic for displaying the navigation menu?
Was This Post Helpful? 0
  • +
  • -

#14 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Re: Navigation Problem

Posted 01 January 2011 - 10:14 AM

View PostJackOfAllTrades, on 01 January 2011 - 11:07 AM, said:

Why don't you explain your logic for displaying the navigation menu?

Well, when you said that what I was doing was repetitive. It is. I did not want to do that, but it was the only way I could get the links to display correctly. I'm going for an accordion style menu. If you click on one it will ease out and display the subcategories of the parent forum. If there was another one open it will ease back in.
Was This Post Helpful? 0
  • +
  • -

#15 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,441
  • Joined: 23-August 08

Re: Navigation Problem

Posted 01 January 2011 - 10:19 AM

Well that's not a PHP thing, that's an HTML/Javascript/CSS thing, isn't it? All PHP does is render HTML to be interpreted by the browser.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2