+ Reply to Thread
Results 1 to 7 of 7

Thread: PHP doNav Function

  1. #1
    Shadow121's Avatar
    Shadow121 is offline x10 Lieutenant Shadow121 is an unknown quantity at this point
    Join Date
    Jul 2006
    Location
    Centerville
    Posts
    455

    PHP doNav Function

    Alright I'm making a forum system of my own and I need help making a breadcrumb trail. This is what I have so far.

    Code:
    function doNav($act){
    		$addonfromHere = "<a href=\"".SITE_LINK."\">Index</a>";
    		$linkNum = count($act);
    		$linksUsed = 1;
    		$linksreturn = "";
    		foreach($act as $links){
    			$linkz[] = $links;
    		}
    		for($i = 0; $i <= $linkNum; $i++){
    			if($linksUsed == 1){
    				$linksreturn = $addonfromHere;
    			}else{
    				$linksreturn .= " &raquo; <a href=\"".SITE_LINK."$links/\">".$linkz[$i]."</a>";
    			}
    			$linksUsed++;
    		}
    		return $linksreturn;
    }
    It only does the 2nd/3rd/4th things and not the first one. Any help with this?
    Last edited by Shadow121; 12-22-2008 at 06:34 PM.

  2. #2
    Scoochi2's Avatar
    Scoochi2 is offline x10 Sophmore Scoochi2 is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Southport!
    Posts
    185

    Re: PHP doNav Function

    Because the first time it is run, the value of $linksUsed is 1, which is set on line 4. After the first run, the value will be 2, then 3 and so on. Which means that on the first iteration of your for loop, $linksreturn will be set to $addonfromHere and it will ignore the else statement.

    To correct this, change line 4 to :
    $linksUsed = 0;

    EDIT: Actually, don't ;)
    Doing so will cause the second link to vanish, AND the first. You could try changing the ==1 to ==0 on line 10 though...
    Last edited by Scoochi2; 12-23-2008 at 09:38 AM. Reason: whoops
    If anyone can see it, my post was meant for anyone who reads it. Don't take it personally or think I'm being condescending... :nuts:

  3. #3
    Shadow121's Avatar
    Shadow121 is offline x10 Lieutenant Shadow121 is an unknown quantity at this point
    Join Date
    Jul 2006
    Location
    Centerville
    Posts
    455

    Re: PHP doNav Function

    I changed it to 0 and it doesn't parse it still :p

  4. #4
    gomarc's Avatar
    gomarc is offline x10 Elder gomarc is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    USA
    Posts
    511

    Re: PHP doNav Function

    Can you post a sample or two with the values of :

    Code:
    $act = ??
    $linksreturn = (Expected output) ??

  5. #5
    Shadow121's Avatar
    Shadow121 is offline x10 Lieutenant Shadow121 is an unknown quantity at this point
    Join Date
    Jul 2006
    Location
    Centerville
    Posts
    455

    Re: PHP doNav Function

    Say I have the following: ?x=ucp&y=password

    I expect it to be User Panel &raquo; Password

  6. #6
    Scoochi2's Avatar
    Scoochi2 is offline x10 Sophmore Scoochi2 is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Southport!
    Posts
    185

    Re: PHP doNav Function

    Quote Originally Posted by Shadow121 View Post
    Say I have the following: ?x=ucp&y=password

    I expect it to be User Panel &raquo; Password
    So how exactly do you call the function?
    PHP Code:
    <?php

    [...]

    echo (
    doNav(array('12345','67890','abcde')));
    ?>
    Using your initial code, I would expect it to show:
    <a href="http://yoursite.com/">Index</a> » <a href="http://yoursite.com/abcde/">67890</a> » <a href="http://yoursite.com/abcde/">abcde</a>


    Note that on line 13, you use the variable $links, but the only other time you used it was in the foreach loop, so you can only assume that your PHP setup is using the last iteration of that foreach as the value for $links.


    I would instead use the following:
    PHP Code:
    function doNav($act){
            
    $output '<a href="http://forums.x10hosting.com/programming-help/'.SITE_LINK.'">Index</a>';
            foreach(
    $act as $link){
                
    $output .= ' &raquo; <a href="http://forums.x10hosting.com/programming-help/'.SITE_LINK.$link.'">'.$link.'</a>';
            }
            return 
    $output;

    Called the same way, the output should now be:
    <a href="http://yoursite.com/">Index</a> » <a href="http://yoursite.com/12345">12345</a> » <a href="http://yoursite.com/67890">67890</a> » <a href="http://yoursite.com/abcde">abcde</a>
    Last edited by Scoochi2; 12-23-2008 at 06:09 PM. Reason: alternative and simpler (and works) code
    If anyone can see it, my post was meant for anyone who reads it. Don't take it personally or think I'm being condescending... :nuts:

  7. #7
    Shadow121's Avatar
    Shadow121 is offline x10 Lieutenant Shadow121 is an unknown quantity at this point
    Join Date
    Jul 2006
    Location
    Centerville
    Posts
    455

    Re: PHP doNav Function

    Alright, I'll try that now. ^_^

    Works like a charm ^_^
    Last edited by Shadow121; 12-23-2008 at 06:59 PM.

+ Reply to Thread

Similar Threads

  1. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  2. PHP Function Disabled???
    By stsights in forum Free Hosting
    Replies: 3
    Last Post: 09-14-2008, 11:53 AM
  3. PHP mail function
    By tearsfall in forum Free Hosting
    Replies: 2
    Last Post: 05-09-2008, 08:58 AM
  4. a little help with php directory function
    By nahsorhseda in forum Scripts & 3rd Party Apps
    Replies: 1
    Last Post: 12-11-2007, 11:50 PM
  5. Sigo con problemas con phpbb2
    By reciecho in forum Soporte
    Replies: 7
    Last Post: 10-20-2007, 06:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers