Jump to content

Menu Not Working Correctly.


VicHost

Recommended Posts

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:

<?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

<?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:

<?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.

Link to comment
Share on other sites

This might not solve your problem, but it's a more logical way to do what you're saying you are.

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

 

Instead, why not:

//if no id defined then load the home page.

if(!isset($_GET['id'])){

header('Location: /index.php');

}

else{

$id = $_GET['id'];

}

Link to comment
Share on other sites

This might not solve your problem, but it's a more logical way to do what you're saying you are.

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

 

Instead, why not:

//if no id defined then load the home page.

if(!isset($_GET['id'])){

header('Location: /index.php');

}

else{

$id = $_GET['id'];

}

 

Thanks mate. I have added that to page.php but now get the following error:

Parse error: syntax error, unexpected '}' in /home/sitevic/public_html/page.php on line 58 so I removed the } from line 58 and it sorted it. However, the two other pages now work fine and the menu responds on those two. But the home button on those two pages still inherit their URL.

Link to comment
Share on other sites

Just to add my Database, just as it may be relevent:

 

-- phpMyAdmin SQL Dump
-- version 3.2.4
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Sep 09, 2010 at 01:43 PM
-- Server version: 5.0.91
-- PHP Version: 5.2.9

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `sitevic_site`
--

-- --------------------------------------------------------

--
-- Table structure for table `content`
--

CREATE TABLE IF NOT EXISTS `content` (
  `id` int(11) NOT NULL auto_increment,
  `title` varchar(255) NOT NULL default '',
  `menutitle` text,
  `startpage` tinyint(1) NOT NULL,
  `last_updated` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `posting_time` timestamp NOT NULL default '0000-00-00 00:00:00',
  `text` text NOT NULL,
  `description` text,
  `keywords` text NOT NULL,
  `position` tinyint(4) NOT NULL default '0',
  `status` tinyint(4) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 PACK_KEYS=0 AUTO_INCREMENT=4 ;

--
-- Dumping data for table `content`
--

INSERT INTO `content` (`id`, `title`, `menutitle`, `startpage`, `last_updated`, `posting_time`, `text`, `description`, `keywords`, `position`, `status`) VALUES
(1, 'Home', 'Home', 1, '2010-09-09 13:30:27', '0000-00-00 00:00:00', 'Welcome to the home page', 'Home page description', 'key,words', 0, 1),
(2, 'About', 'About', 0, '2010-09-09 13:42:48', '0000-00-00 00:00:00', 'This is the about page', NULL, '', 0, 1);

Link to comment
Share on other sites

Fixed.

 

I changed this code in nav.php:

$startpage = $row['startpage'];
$href = "page.php?id=$id";
if ($startpage == 1) {
	$href = "";
	}

to this:

$startpage = $row['startpage'];
$href = "page.php?id=$id";
if ($startpage == 1) {
	$href = "/";
	}

Note, including / as the $href for startpage

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.