Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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