GlenR GlenR - 27 days ago 12
CSS Question

Apply CSS class to clicked link from multiple links to same page, different sections

I have 3 links that all point to the same page but to different sections.

This is what the page sections look like, they are all similar- just read from different tables.

include 'inc/connect.php';
$data = mysqli_query($link, "SELECT * FROM networking WHERE id = 1")or
while($info = mysqli_fetch_array( $data )) {
echo nl2br($info['info']);}

This is the part of the menu file that has a link to 'Networking'.

if ($page == 'system') {
$output .="<li><a href='system.php#networking' class='active'>Networking</a></li>";}
$output .="<li><a href='system.php#networking'>Networking</a> </li>";}

All the page section are in a page called system.php.
In the head of system.php I have this line

<?php $page = 'system'; ?>

This so I can apply the css class 'active' to the active link.

The way it is now, when I click on any 1 of my same page different section link the the class 'active' is applied to all 3 menu items.

Is there a way that I can apply the class to only the clicked link?

Answer Source

I understand your problem, you could do something like this:


And do this at the top:

<?php $page = 'system'; $section=$_GET['section']; ?>

And then change your if statement to:

if ($page == 'system' AND $section == 'networking') { 

Note: this is not the best solution, but uses your style, I hope this will help you!