Hey,
I relocated this question to the PHP forum because it is not longer a JS issue (at least I think)
I have a very simple navbar which has an active state which changes on click. Now I wanted to use this navbar to order a PHP/SQL generated table.
However the way the table gets order is by using a variable which changes the php extension in the URL on click. So everytime I click the link in the navbar it resets because the extension changes (I'm guessing).
I looked online and I found a few example of how to do this when you have different php pages but I could not find anything that explained how to do it if just the php extension changes.
Here is the setup
JS function for navbar:
Divs with php linksCode:$(document).ready (function() { $("a.cp_btns").click(function() { $("a.cp_btns.active").removeClass("active"); $(this).addClass("active"); }); });
As you can see the $id_var etc. change the php extensionCode:<div id="cp_menu"> <a class="cp_btns "<?php echo'<a href="indexB.php?order_var=' . $id_var . '"';?>>Most Recent</a></a> <a class="cp_btns" <?php echo'<a href="indexB.php?order_var=' . $fn_var . '"';?>>Best Rated</a></a> <a class="cp_btns" <?php echo'<a href="indexB.php?order_var=' . $ln_var . '"';?>>Most Viewed</a></a> </div>
One of the examples I found does something like this
But as I said that only seems to be useful if the navbar links to different php pages.Code:<? $path = $_SERVER['PHP_SELF']; $page = basename($path); $page = basename($path, '.php'); ?> <div id="navbar"> <ul> <li><a<? if($page == 'one') print ' class="active"'; ?> href="one.php">Page 1</a></li> <li><a<? if($page == 'two') print ' class="active"'; ?> href="two.php">Page 2</a></li> <li><a<? if($page == 'three') print ' class="active"'; ?> href="three.php">Page 3</a></li> <li><a<? if($page == 'four') print ' class="active"'; ?> href="four.php">Page 4</a></li> </ul> </div>
Is there perhaps a way to hide the extension or would that not work?
Thanks
Shibbs



Reply With Quote
Bookmarks