Help me, please Toby.

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Waay back in February, you said ...

(reusing a navigation block throughout a site)

It's possible to do that, but still avoid linking to the page you're
already on!

    $nav = array(
        'Home'        => '/',
        'Products',    => '/products.php',
        'Contact'    => '/contact_us.php'

    print "<ul>\n";
    foreach ($nav as $title => $file)
        if ($_SERVER['PHP_SELF'] == $file)
            print "\t<li></li>\n";
            print "\t<li><a href=\"\">"
                . "</a></li>\n";
    print "</ul>\n";

I thought "You beauty!, and put it aside until I knew something about
I tried putting the code in a file called "headsup.php" and putting the
line <?php include('headsup.php'); ?>  at the start of each file.
Trouble is, I can't get the darn thing to work. It always wants to do
the "else" bit. Can you help? I've amended the top bit as follows

    $nav = array(
        'Home'        => './index.php',
        'Products'    => './products.php',
        'Contact Us'    => './contact.php'

Thanks in advance. I'm learning a lot from hanging out here.

Re: Help me, please Toby.

Deciding to do something for the good of humanity, Joe

Quoted text here. Click to load it

Well, that should tell you the problem. Remove the '.' you've added at
the beginning of each, and it should work.

Mark Parnell
My Usenet is improved; yours could be too:

Re: Help me, please Toby.

On Fri, 14 Jul 2006 11:23:25 +1000, Mark Parnell put finger to
keyboard and typed:

Quoted text here. Click to load it

To explain that a little further...

The script, as writen, requires an absolute URL for each page (ie, one
begining with a /) in the comparison. A relative URL (beginning with
./) won't work as it will never match.

If you want to match on relative URLs, then that's possible but a bit
more complex - it will mean changing the script, not just the data in
the array.

Please give me one!

Re: Help me, please Toby.

Mark Goodge wrote:

Quoted text here. Click to load it

Yep -- what he said.

Toby A Inkster BSc (Hons) ARCS
Contact Me  ~

Re: Help me, please Toby. says...
Quoted text here. Click to load it
Thanks Mark and Toby. I was ""this close! Back to the drawing board for

Re: Help me, please Toby. says...
Quoted text here. Click to load it
I wish. I get -
"Not Found
The requested URL /products.php was not found on this server."
I guess that's because they're actually in

The way I had it found the files and made the menu, just wouldn't NOT
make every item a link.

oh. I see.

So I can't use
./ = this directory
../ = one directory up
but I can use / = root.
Why's that, then?

Site Timeline