Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 07-04-2005, 07:55 AM Navigation...
sameer785's Avatar
Super Talker

Posts: 115
Location: Kathmandu,Nepal
Trades: 0
I was trying to build a navigation menu which is included in all the pages of the site. Is a there a way to remove the links from the current page for eg. (if a viewer is viewing the page Contents/meat.php the key meat in the navigation bar would not have a link at all.

I have hust some basic knowledge of php and haven't gone too far.I have used it mostly for including pages. Here's some example code of the nav.
<?php
$navigation=array('Home' => '/index.php',
'Meat' => '/Contents/meat.php',
'Fish' => '/Contents/fish.php',
'Eggs' => '/Contents/eggs.php',);
print "<table> \n";
foreach ($navigation as $key => $value){
print"<tr><td><a href=\"$value\">$key</a></td></tr>\n";
}
print"<table> \n";


?>

Any help would be much much appreciated.
__________________

Please login or register to view this content. Registration is FREE

Last edited by sameer785; 07-04-2005 at 07:57 AM..
sameer785 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-04-2005, 03:17 PM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
hey there sameer785, nice to see you're struggling with PHP :P

In answer to your question, i think the code below should work fine, but i'm not totally sure!

PHP Code:
<?php
$navigation 
=     array(    'Home' => '/index.php',
            
'Meat' => '/Contents/meat.php',
            
'Fish' => '/Contents/fish.php',
            
'Eggs' => '/Contents/eggs.php',);
print 
"<table> \n";

foreach (
$navigation as $key => $value){

print
"<tr><td>";

    if (
$_SERVER['PHP_SELF'] != $value) {
        print 
"<a href=\"$value\">$key</a>";
    } else {
        print 
$key;
    }

print 
"</td></tr>\n"

}

print
"<table> \n";
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
leavethisplace is offline
Reply With Quote
View Public Profile
 
Old 07-04-2005, 11:32 PM
sameer785's Avatar
Super Talker

Posts: 115
Location: Kathmandu,Nepal
Trades: 0
Thanks leavethisplace.
I am really struggling with php. This is the first time I have used it in any website.
You solution worked. But a litle problem has arisen once again. All these link in the navbar had their own link titles. These are defined in the second array $titles. I tried to use for and foreach to iterate thrugh the array to add the link titles to these links. But it kept on giving unexpected results. When using nested foreach loops, for 4 links and 4 titles, it showed 16 links.
Again, when you are viewing a page that's in the navbar, its link will be automatically cut off and it will appear simply as text. So the link titles will be misplaced.[i am getting confused myself explaining this.]
Like in the array $navigation, the first link is Home. In the array $title, the first title is 'Welcome to our restaurant.' Now when you are viewing the home page, the first key in the $title array will go the second link. i.e because the first will not contain a link at all the link meat will have title 'Welcome to our restaurant'.
Everyone, please help me out of this.
Hope my problem is understood although I couldn't explain it that clearly.
__________________

Please login or register to view this content. Registration is FREE
sameer785 is offline
Reply With Quote
View Public Profile
 
Old 07-05-2005, 07:59 AM
sameer785's Avatar
Super Talker

Posts: 115
Location: Kathmandu,Nepal
Trades: 0
I think I found the solution myself.I just used a multidimensional array. Didn't know there could be one, just learnt it today. For those who might find it useful, here's the code.
PHP Code:
$navigation=array('Home' => array('/index.php' => 'The Restaurateur - At your service'),
                    
'Meat' => array('/Contents/meat.php'=> 'Meaty stuff'),
                    
'Fish' => array('/Contents/fish.php'=> 'Fishy stuff'),
                    
'Eggs' => array('/Contents/eggs.php'=> 'Eggy stuff',));
print 
"<table> \n";
foreach(
$navigation as $link_text=> $actual_link){
        foreach(
$actual_link as $link=> $linktitle){
        print
"<tr><td>";
        if(
$_SERVER['PHP_SELF']!=$link){
        print 
"<a href=\"$link\" title=\"$linktitle\" target=\"_top\">$link_text</a>";
        }
        else{
        print
"$link_text";
        }
        print
"</tr></td>";
        }
    }
print
"</table>"
__________________

Please login or register to view this content. Registration is FREE
sameer785 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Navigation...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.89200 seconds with 12 queries