I need help with PHP , please help with a simple code

Discussion in 'PHP' started by FR3@K, Oct 2, 2007.

  1. #1
    I want to make a Navigation system using php.

    I have it on html , but i am having problems to edit it for every page.
    i want to include it on every page usng php

    here is the html code

    <ul class="mainmenu">
    <li id="current" class="level2 item1"><a href="/index.html">Home</a></li>
    <li class="level2 item10"><a href="/soft.html"">Softwares</a></li>
    <li class="level2 item11"><a href="/stats/downloads.php">CS Tools</a></li>
    <li class="level2 item12"><a href="/forum/index.php">Forum</a></li>
    <li class="level2 item14"><a href="">Contact Us</a></li>
    </ul>
    Code (markup):

    now as u can see there is an id names as "current" .
    I want it to work like this.

    include_once "nav.php";

    <?php include"$home"; ?> -> this one should include whole nav system and make the id of first link to Current.

    on another page of my website.

    include_once "nav.php";

    <?php include"$soft"; ?> -> this one should include whole nav system and make 2nd link's id to current.


    can anyone please help me ??
     
    FR3@K, Oct 2, 2007 IP
  2. sdemidko

    sdemidko Member

    Messages:
    81
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #2
    you are not familiar with php, pm me if you are able to pay some for this...
     
    sdemidko, Oct 2, 2007 IP
  3. michaeljdennis

    michaeljdennis Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Here is my favorite way so far to do that.

    http://www.alistapart.com/articles/keepingcurrent/
     
    michaeljdennis, Oct 2, 2007 IP
  4. kendo1979

    kendo1979 Peon

    Messages:
    208
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    php won't work that way

    you can put
    <ul class="mainmenu">
    <li id="current" class="level2 item1"><a href="/index.html">Home</a></li>
    <li class="level2 item10"><a href="/soft.html"">Softwares</a></li>
    <li class="level2 item11"><a href="/stats/downloads.php">CS Tools</a></li>
    <li class="level2 item12"><a href="/forum/index.php">Forum</a></li>
    <li class="level2 item14"><a href="">Contact Us</a></li>
    </ul>
    Code (markup):
    onm nav.php

    but when you include nav.php, the whole code will get included.

    to change the id accordingly, make it a variable, and pass the value to it.

    so something like

    nav.php
    <ul class="mainmenu">
    <li id="$navid" class="level2 item1"><a href="/index.html">Home</a></li>
    <li class="level2 item10"><a href="/soft.html"">Softwares</a></li>
    <li class="level2 item11"><a href="/stats/downloads.php">CS Tools</a></li>
    <li class="level2 item12"><a href="/forum/index.php">Forum</a></li>
    <li class="level2 item14"><a href="">Contact Us</a></li>
    </ul>
    Code (markup):
    then on your other file

    $navid = $home or $navid = home
    include nav.php
     
    kendo1979, Oct 2, 2007 IP
  5. FR3@K

    FR3@K Banned

    Messages:
    182
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    no you dont understand.
    i want the id to be chnaged to "current" on different pages.
    for example on index.php it should change the id of first link to current.
    and on soft.html it should change the id of second link to current and remove the id of first link.
    i think if and else statement would work here.
     
    FR3@K, Oct 3, 2007 IP
  6. scriptman

    scriptman Peon

    Messages:
    175
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    He didn't understand, but michaeljdennis did. Did you read the article he posted? It was exactly what you wanted.

    Actually I think the method described in the article is slightly inefficient in that it needlessly checks the page name after it has already been set. I would suggest using a switch rather than multiple IFs. How you implement that exactly will depend on your templating engine (if any). Here is an example of my code:

    if(isset($page))
    {
    	switch ($page)
    	{
    		case 'INDEX':
    			break;
    		case 'BROWSE':
    			break;
    		case 'REGISTER':
    			break;
    		case 'LOGIN':
    			break;
    		default:
    			$page = '';
    	}
    	
    	if(!empty($page))
    	$template->assign_tags(array($page.'_SELECTED' =>'class="selected"'));
    }
    Code (markup):
    (This is all specific to my classes etc, but it should illustrate my point. That code is about 5 minutes old and not bug-tested so don't blindly copy chunks of it!

    Good luck!

    Edit: Just to make things clear, you stick something similar to the above code in whatever PHP include you are using for common processing, then set $page before the include in your actual end-user PHP pages. Example:

    $page = 'HOME';
    include('common.php');

    //Stuff.
     
    scriptman, Oct 3, 2007 IP
  7. FR3@K

    FR3@K Banned

    Messages:
    182
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    yeah thanks i already read the article.
    and just testing needed.
    already updated my codes.

    and one more thing please.

    i also want to update a class on a seperate navigation system.
    can you help me?
    the code is :

    <ul class="mainmenu">
    <li class="level1 item2 parent active" style="background: url('images/menu_item1_bg.png') no-repeat;"><a class="slider" href="index.html">Home</a></li>
    <li class="level1 item4 parent" style="background: url('images/menu_item2_bg.png') no-repeat;"><a class="slider" href="/soft.html">Softwares</a></li>
    <li class="level1 item6 parent" style="background: url('images/menu_item3_bg.png') no-repeat;"><a class="slider" href="/stats/downloads.php">CS Tools</a></li>
    <li class="level1 item7 parent" style="background: url('images/menu_item4_bg.png') no-repeat;"><a class="slider" href="/forum/index.php">Forum</a></li>
    <li class="level1 item8 parent" style="background: url('images/menu_item5_bg.png') no-repeat;"><a class="slider" href="">Contact Us</a></li>
    </ul>
    Code (markup):
    Now as you can see there is a class called active on home's tab.
    I want this class to be added on soft's tab when clicked , and to be removed from home's tab.

    can you help me?
    remember just updating of "active" is needed , everything remains same.
     
    FR3@K, Oct 3, 2007 IP
  8. scriptman

    scriptman Peon

    Messages:
    175
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Isn't that essentially the same as your initial problem except with a different HTML class name inserted? It looks like you can just reuse the code you've currently got for the initial problem (You might want to consider turning it into a function if you have nested tab navigation or something along those lines).
     
    scriptman, Oct 3, 2007 IP
  9. FR3@K

    FR3@K Banned

    Messages:
    182
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    ok thanks everyone for help , i sorted it out myself.
    thanks for help michaeljdennis and everyone.
     
    FR3@K, Oct 3, 2007 IP
  10. FR3@K

    FR3@K Banned

    Messages:
    182
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    no , wait , the code doesnt works.
    so i am still looking for someone to sort the code for me.
     
    FR3@K, Oct 3, 2007 IP
  11. michaeljdennis

    michaeljdennis Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    ........Hahahahahahahahahahahaha!
     
    michaeljdennis, Oct 3, 2007 IP
  12. FR3@K

    FR3@K Banned

    Messages:
    182
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    hey michealdennis , +rep coming for you.
    i needed to customize the code a bit.
    but i got it working :D thanks.
     
    FR3@K, Oct 4, 2007 IP
  13. michaeljdennis

    michaeljdennis Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    No problem man! I've used that technique quite a few times now. Enjoi!

    EL OH EL at teh guy asking for payment!!1!
     
    michaeljdennis, Oct 15, 2007 IP