Jump to content

[SOLVED] php navigation question ...


imarockstar

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/133106-solved-php-navigation-question/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.