Jump to content

Recommended Posts

I'm trying to make a master menu for my site.

 

I'm trying to use php to avoid having all those lines in every single page.

 

 

 

 

 

here is what i got for my menu

<?php
<div id="menu">
   <ul>
      <li<?php if ($_GET["page"] == "home" || !(isset($_GET["page"]))) echo " id=\"current\""; ?>><a href="index2.php">Home</a></li>
      <li<?php if ($_GET["page"] == "forums") echo " id=\"current\""; ?>><a href="index.php">Forums</a></li>
      <li<?php if ($_GET["page"] == "download") echo " id=\"current\""; ?>><a href="index3.php">Download</a></li>
      <li<?php if ($_GET["page"] == "contact") echo " id=\"current\""; ?>><a href="#">Contact</a></li>
      <li<?php if ($_GET["page"] == "help") echo " id=\"current\""; ?>><a href="#">Help</a></li>
      <li<?php if ($_GET["page"] == "other") echo " id=\"current\""; ?>><a href="#">Other</a></li>        
   </ul>        
</div>

 

here is what i got in CSS;

#menu {
clear: both;	
margin: 0; padding: 0 40px 0 0;
font:12px/26px Tahoma, Sans-serif;
text-transform: uppercase;
height: 26px;
}
#menu ul {
float: left;
list-style: none;
margin:0; padding: 0;
}
#menu ul li {
display: inline;
}
#menu ul li a {
display: block;
float: left;
padding: 0 8px;
color: black;	
text-decoration: none;
}
#menu ul li a:hover {
background-color: #666;
color: #cccccc;	
}
#menu ul li #current{	
background-color: #474A41;
color: #333;
}

 

How do i set my page with $_GET["page"] so the menu will work?

 

Link to comment
https://forums.phpfreaks.com/topic/90134-solved-php-menu-css/
Share on other sites

So the menu would work? It already works. If the $_GET is one of the links in the menu, its ID is "Current", which is the page the user is at. To make the pages using $_GET

 

do

 

$page = $_GET['page'];
$page = (isset($page)) ? $page : "Home";

switch($page){

case 'Home':

echo 'this is home';

break;

case 'Forum':

echo " HALLO THIS IS THE FORUMS";

break;

default:
echo "Page does not exists";
}

Link to comment
https://forums.phpfreaks.com/topic/90134-solved-php-menu-css/#findComment-462218
Share on other sites

@phpSensei

 

The menu in my first post doesn't work. How do i define those pages?

I get error like this

 

    * Notice: Undefined index: page in C:\Documents and Settings\8\Desktop\wamp\www\forums\header.php on line 14

      id="current">Home

    *

 

      Notice: Undefined index: page in C:\Documents and Settings\8\Desktop\wamp\www\forums\header.php on line 15

      >Forums

    *

 

      Notice: Undefined index: page in C:\Documents and Settings\8\Desktop\wamp\www\forums\header.php on line 16

      >Download

    *

 

      Notice: Undefined index: page in C:\Documents and Settings\8\Desktop\wamp\www\forums\header.php on line 17

      >Contact

    *

 

      Notice: Undefined index: page in C:\Documents and Settings\8\Desktop\wamp\www\forums\header.php on line 18

      >Help

    *

 

      Notice: Undefined index: page in C:\Documents and Settings\8\Desktop\wamp\www\forums\header.php on line 19

      >Other

 

also,

 

$page = $_GET['page'];
$page = (isset($page)) ? $page : "Home";

switch($page){

case 'Home':

echo 'this is home';

break;

case 'Forum':

echo " HALLO THIS IS THE FORUMS";

break;

default:
echo "Page does not exists";
}

 

I get "undefined index page" for this one too.

 

 

Link to comment
https://forums.phpfreaks.com/topic/90134-solved-php-menu-css/#findComment-462238
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.