Jump to content


Photo

PHP Navigation help


  • Please log in to reply
4 replies to this topic

#1 ThEMakeR

ThEMakeR
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 17 August 2006 - 01:02 PM

Hi again,

I have developed some code for a PHP navigation system, similar to a tutorial I recently looked at, but I'm not sure how I make the appropriate cat_x.php page appear when a link, <a href.... </a>, is clicked. The code 'script' I am using is:

Script:
<?php
if ($p == "") {
		include "v3/catalogue.php"; }

elseif ($p == "cat_1.php") {
		include "v3/cat_1.php"; }
		 
elseif ($p == "cat_2.php") {
		include "v3/cat_2.php"; }
		 
elseif ($p == "cat_3.php") {
		include "v3/cat_3.php"; }

elseif ($p == "cat_4.php") {
		include "v3/cat_4.php"; }

elseif ($p == "cat_5.php") {
		include "v3/cat_5.php"; }

else {
		include "v3/error.php"; }
?>

What I need to happen:
I need to be able to click a link on a page called "catalogue.php", have the variable(?) $p select the appropriate cat_x.php page and display its contents, its catalogue items rather, on the page.

How do I get around this??

To help a bit more I am including the full code for my page:
<?php
   include "header.php";
?>

<br />
<div align="center">
<img src="images/cat_img.gif" alt="Martin & D'almeida antique catalogue 2006" />
<br />
<font>Click the desired catalogue link to see those items</font>
<br /><br />
<a href="http://www.manddantiques.com/catalogue.php?p=cat_1.php"><img src="images/cat_1.jpg" alt="Urns and Ornaments catalogue of stock" height="140" width="100" /></a>
<a href="http://www.manddantiques.com/catalogue.php?p=cat_2.php"><img src="images/cat_2.jpg" alt="Carvings and Sculptures catalogue of stock" height="140" width="100" /></a>
<a href="http://www.manddantiques.com/catalogue.php?p=cat_3.php"><img src="images/cat_3.jpg" alt="Garden Statuary catalogue of stock" height="140" width="100" /></a>
<a href="http://www.manddantiques.com/catalogue.php?p=cat_4.php"><img src="images/cat_4.jpg" alt="Decorative Items catalogue of stock" height="140" width="100" /></a>
<a href="http://www.manddantiques.com/catalogue.php?p=cat_5.php"><img src="images/cat_5.jpg" alt="Chimney and Fire Pieces catalogue of stock" height="140" width="100" /></a>
<br />
<a href="http://www.manddantiques.com/catalogue.php?p=cat_1.php">Urns &amp; Ornaments</a>
<a href="http://www.manddantiques.com/catalogue.php?p=cat_2.php">Carvings &amp; Sculptures</a>
<a href="http://www.manddantiques.com/catalogue.php?p=cat_3.php">Garden Statuary</a>
<a href="http://www.manddantiques.com/catalogue.php?p=cat_4.php">Decorative Items</a>
<a href="http://www.manddantiques.com/catalogue.php?p=cat_5.php">Chimney &amp; Fire Pieces</a>
<br /><br />
<font><u>All items are for sale unless otherwise stated</u></font>
</div>

<?php
   include "footer.php";
?>

Have I gone about it the wrong way?! Please spend a small few minutes helping me if you can, thanks very much to anyone who lends a hand. Its very appreciated!

#2 Ifa

Ifa
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationRauma, Finland

Posted 17 August 2006 - 01:06 PM

<?php
$p = $_GET["p"];
if ($p == "") {
....

I'm just a guy who likes to code for fun...

#3 ThEMakeR

ThEMakeR
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 17 August 2006 - 01:39 PM

I might have to start from scratch because I cant get it to work.

Anyone got a script they use that will work with a link system?

#4 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 17 August 2006 - 01:43 PM

<?php

$p = '';
if (!empty($_GET['p'])) $p = $_GET['p'];

switch ($p) {

    case 'cat_1':
        include $p . '.php';
        break;
 
    /* snip.. */

    default: 
        include 'default.php';

}


//etc.


#5 Ifa

Ifa
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationRauma, Finland

Posted 17 August 2006 - 01:58 PM

include $p;
as
?p=cat_1.php
and so on
I'm just a guy who likes to code for fun...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users