Log in

View Full Version : Resolved Current Page



john0611
08-05-2009, 07:10 AM
Hi all, I've been trying to work this one out?



<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!

Schmoopy
08-05-2009, 01:08 PM
Do you mean something like this? :



<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.

john0611
08-05-2009, 10:36 PM
Fantastic! Just the job.

Thanks for your help Schmoopy.