imarockstar Posted November 17, 2008 Share Posted November 17, 2008 I have this bit of code <?php // Retrieve data from database $sql="SELECT * FROM homeblocks"; $result=mysql_query($sql); // Start looping rows in mysql database. while($rows=mysql_fetch_array($result)){ ?> <div class='navlink'><a href='?=<? echo $rows['id']; ?>'><? echo $rows['title']; ?></a></div> <? } ?> it works great, however when a user clicks on a link and goes to that page I need the CLASS of the div to change to "navlinkactive". How can I do this with PHP ? thanks b Quote Link to comment https://forums.phpfreaks.com/topic/133106-solved-php-navigation-question/ Share on other sites More sharing options...
premiso Posted November 17, 2008 Share Posted November 17, 2008 Depending on how you call the page I would do this: <?php // Retrieve data from database $sql="SELECT * FROM homeblocks"; $result=mysql_query($sql); // Start looping rows in mysql database. while($rows=mysql_fetch_array($result)){ if (isset($_GET['page']) && $_GET['page'] == $rows['id']) { echo "<div class='navlinkactive'><a href='?page=" . $rows['id'] . "'>" . $rows['title'] . "</a></div> "; }else { echo "<div class='navlink'><a href='?page=" . $rows['id'] . "'>" . $rows['title'] . "</a></div> "; } } ?> NOTE:::: You may have to change your script where you used to just use ?= to use page now. Quote Link to comment https://forums.phpfreaks.com/topic/133106-solved-php-navigation-question/#findComment-692216 Share on other sites More sharing options...
imarockstar Posted November 17, 2008 Author Share Posted November 17, 2008 awesome ya that worked great !!! Quote Link to comment https://forums.phpfreaks.com/topic/133106-solved-php-navigation-question/#findComment-692236 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.