Well, Following is the function which select current page name. ex: index.php, owner.php, contactus.php etc. I created this function because i need to active a css id(#active) selector which highlight the current page.
Function
function curPageName() {
return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}
$pagename = curPageName();
And this is my Navigation Code:
<ul>
<li><a href="index.php" <?php if($pagename == "index.php") echo "id='active'";
?>>HOME</a></li>
<li><a href="owner.php" <?php if($pagename == "owner.php") echo "id='active'"; ?>>LIST
YOUR PROPERTY</a></li>
<?php
$menu = mysql_query("SELECT * FROM page where status = 1");
while($re = mysql_fetch_array($menu))
{
$pageid = $re['pageid'];
$pagelink = $re['pagelink'];
$pagename = strtoupper($re['pagename']);
$pagedes = $re['pagedes'];
echo "<li><a href='page.php?pageid=$pageid'>$pagename</a></li>";
}
?>
<li><a href="contactus.php" <?php if($pagename == "contactus.php") echo "id='active'";
?>>CONTACT US</a></li>
</ul>
So, My questions is It’s active the css id selector to Index.php and owner.php. BUT It’s doesn’t active the css selector to contactus.php page.
Is there anything wrong in my code?
You have overwritten
$pagenameintowhile loop