• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Menu Not Working Correctly

Dan

Bullah
NLC
Ok, I have most of my CMS done. I have the data being displayed from the database. I also have the code working to create new pages and menu items. However, I am faced with two issues.

1. The menu will not display horizontally. This is not a major issue but would be good for people who use my script to be given that option if they want to modify the template.

2. Each page has an ID that is created in the database. The script creates a new page and tells the database to define a new ID for each page. For example page.php?id=2 This works fine. But, if I go to say page.php?id=2 and then click on the Home button to go back to the index, the home button also inherits the same URL as the page with the ID. I also noticed that any link on the page with the id= defined, also inherits that URL. I am unable to figure it out and was hoping someone here could help.

Here is the page.php code:
Code:
<?php
/*****************************
*
* Name: osPHPSite
* Version: 0.0.1
* Developer: Dan O'Riordan
* Email: dan@vichost.com
* Copyright (c) 2010 VicHost
* Date: September 2010
* Website: www.osphpsite.com
* Licence: GNU/GPL v3
*
******************************/
include "language/english/english.php";
include "includes/settings.php";
include "includes/version.php";
include "includes/config.php";
include "templates/default/header.tpl";
include "nav.php";
?>
                <div class="art-content-layout">
                    <div class="art-content-layout-row">
                        <div class="art-layout-cell art-content">
                            <div class="art-post">
                                <div class="art-post-body">
                            <div class="art-post-inner art-article">
<?php 

//if no id defined then load the home page.
if(isset($_GET['id'])){
$id = $_GET['id'];

if(!is_numeric($id)){
    include "includes/404.php";
    exit;
}

database_connect();
$query = "SELECT * from content where id = $id;";
$echo = mysql_error();
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);

if ($num_rows == 0) {
    include "includes/404.php";;
    exit;
}

while ($row = mysql_fetch_assoc($result)) {
        $title = $row['title'];
        $text = $row['text'];
        $description = $row['description'];
        $keywords = $row['keywords'];
    }
}
include("includes/body.php");
?>
                            </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
<?php include "templates/default/footer.tpl"; ?>

This creates the pages defined in the database and also tells nav.php to create a new menu item.

And here is the nav.php
Code:
<?php 
database_connect();
$query = "SELECT * from content
          WHERE status = 1
          ORDER by position;";
$error = mysql_error();
if (!$result = mysql_query($query)) {
    print "$error";
	exit;
	}

$result = mysql_query($query);	
while ($row = mysql_fetch_assoc($result)) {
$id = $row['id'];
$menutitle = $row['menutitle'];

//if no menu title entered, then use the title.
if ($menutitle == ""){
	$menutitle = $row['title'];
}

$startpage = $row['startpage'];
$href = "page.php?id=$id";
	if ($startpage == 1) {
		$href = "";
		}
?>
                                                            <ul class="art-vmenu">
                                                            	<li>
                                                            		<a href="<?php echo $href; ?>"><span class="l"></span><span class="r"></span><span class="t"><?php echo $menutitle; ?></span></a>
                                                            	</li>
                                                            </ul>
<?php
}
?>
The HTML part of this relies on CSS for the layout. At the moment I have the menu displayed virtically, until I can figure out the horizontal bit
body.php:
Code:
<?php
database_connect();
$navquery = "SELECT * from content
          WHERE status = 1
          ORDER by position;";

$navresult = mysql_query($navquery);   
while ($row = mysql_fetch_assoc($navresult)) {
$navid = $row['id'];
$menutitle = $row['menutitle'];
$startpage = $row['startpage'];
//if no menu title entered, then use the title.
    if ($menutitle == ""){
        $menutitle = $row['title'];
    }

if ($startpage == 1) {
    $href = "/";
}else{
    $href = "page.php?id=$navid";
    }
$startpage = NULL;
} echo $text;
?>

Can anyone see where I am going wrong? Any help would be appreciated.
 
Those who were wondering, I fixed this by simply adding a / to:

Code:
$startpage = $row['startpage'];
$href = "page.php?id=$id";
    if ($startpage == 1) {
        $href = "/";
        }
 
You do realize that you can use <?=$VAR;?> instead of <?php echo $VAR; ?> This will help to speed up your programming. Aside from that. Why not also replace;
if ($startpage == 1) {
$href = "/";
}
with
$startpage = $row['startpage'];
(($startpage==1) ? $href = "page.php?id=$id" : $href="/");
Saves on extra line executions when executing the PHP.

Also, ending the PHP (I.E. ?>) midway, can add execution time.
Maybe what you should look at, as an option to prevent half loaded pages due to packet loss is to temporarily store the output of your WHILE statement's ECHOs in a variable;
I.E;
$var = '10';
$output = ""; //Set the output to avoid PHP errors.
while($var != '0'){
$output .= "Count: ".$var."<br />";
$var --;
}
echo $output;

Very simple code, what it does is count down to 1, from 10. And basically, it will output the entire results all in 1 go, rather then outputting the results as they are being made.
Basically, this gives the illusion of a faster load time, and prevents distorted designs that occur to packet loss.

Using programming methods like exampled above, can assist in decreasing execution time, by combining statements on single lines, as PHP it's self, is read on a per line basis...
The smaller the amount of coding, the faster the execution. =D
 
Back
Top