Results 1 to 3 of 3

Thread: Current Page

  1. #1
    Join Date
    Mar 2009
    Posts
    42
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default Current Page

    Hi all, I've been trying to work this one out?

    Code:
    <ul>
    <?php /* current page */ $currentPage = basename($_SERVER['SCRIPT_NAME']); ?>
    
    	<li><a href="about_the_artist.php" <?php if ($currentPage == 'about_the_artist.php') {echo 'id="select"';} ?>>Introduction</a></li>
    
        <li><a href="c._v._&amp;_exhibitions.php" <?php if ($currentPage == 'c._v._&_exhibitions.php') {echo 'id="select"';} ?>>C.V. / Exhibitions</a></li>
    
        <li><a href="#">Buy Prints</a></li>
    
    </ul>
        
        <h2>The Decades:</h2>
    
    <?php
    //echo linked results from db
    	// query db
    	$sql = mysql_query ("SELECT * FROM `decades` ORDER BY ID ASC");
    	// echo linked result from db
    	while ($row = mysql_fetch_assoc($sql)){
    	echo "<ul><li>" . "<a href='the_decades.php?ID={$row['ID']}'>" . ($row['Date']) . "</a></li></ul>";
    // I'm not too sure here?
    	if ($currentPage == 'the_decades.php?ID={$row[ID]}') {echo 'id="select"';}
    
    }
    ?>
    What I would like to do is echo the linked results from the DB which works perfect, but when the user selects and clicks on the link I would like to have it highlighted to indicate current page. (id="select") is the a:hover from style sheet.

    Any ideas would be great!
    Last edited by john0611; 08-05-2009 at 10:37 PM.

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Do you mean something like this? :

    PHP Code:
    <ul>
    <?php /* current page */ $currentPage $_SERVER['SCRIPT_NAME'];
        
    /*  full path URL, including query*/    $fullpath basename($_SERVER['REQUEST_URI']); // e.g. -> the_decades.php?ID=59
    ?>

        <li><a href="about_the_artist.php" <?php if ($currentPage == 'about_the_artist.php') {echo 'id="select"';} ?>>Introduction</a></li>

        <li><a href="c._v._&amp;_exhibitions.php" <?php if ($currentPage == 'c._v._&_exhibitions.php') {echo 'id="select"';} ?>>C.V. / Exhibitions</a></li>

        <li><a href="#">Buy Prints</a></li>

    </ul>
        
        <h2>The Decades:</h2>

    <?php



    //echo linked results from db
        // query db
        
    $sql mysql_query ("SELECT * FROM `decades` ORDER BY ID ASC");
        
    // echo linked result from db
        
    while ($row mysql_fetch_assoc($sql)){
        echo 
    "<ul><li>" "<a href='the_decades.php?ID={$row['ID']}' "; echo ($fullpath == "the_decades.php?ID={$row['ID']}") ? 'id="select"' ''; echo ">" . ($row['Date']) . "</a></li></ul>";
    }
    ?>
    The way you have it at the moment, using $_SERVER['SCRIPT_NAME'] you can't get the full query, so it just gets the page name, instead of grabbing the rest of it (everything after the question mark).

    I think this is what you want, but just say if this doesn't work for you.

  3. The Following User Says Thank You to Schmoopy For This Useful Post:

    john0611 (08-05-2009)

  4. #3
    Join Date
    Mar 2009
    Posts
    42
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Thumbs up

    Fantastic! Just the job.

    Thanks for your help Schmoopy.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •