I have this code, which creates the pages, taken from the DB:

function subject_navigation($connection){
$sqlCommand = "SELECT id, linknavn, pos FROM subjects ORDER BY pos ASC";
$query = mysqli_query($connection, $sqlCommand) or die (mysqli_error());																														   			

while ($row = mysqli_fetch_array($query)) {
    $sid = $row['id'];
    $linklabel = $row['linknavn'];																														   			
	echo '<li><a href="index.php?sid=' . $sid . '&amp;' . $linklabel . '" title="' . $linklabel . '">' . $linklabel . '</a></li>';
}
mysqli_free_result($query);	
}

I have in vain been trying to create a small script that echoes out a selected class, when a page is active/clicked - but without succes.

How can I modify this line, so the active link echoes out the selected css class?

echo '<li><a href="index.php?sid=' . $sid . '&amp;' . $linklabel . '" title="' . $linklabel . '">' . $linklabel . '</a></li>';
function subject_navigation($connection){
$sqlCommand = "SELECT id, linknavn, pos FROM subjects ORDER BY pos ASC";
$query = mysqli_query($connection, $sqlCommand) or die (mysqli_error());																														   			
$active='';
while ($row = mysqli_fetch_array($query)) {
$sid = $row['id'];
$linklabel = $row['linknavn'];
if($sid == $_GET['sid']){
	$active = 'class="active_link"';	
	}else{
        $active = 'a class="inactivelink"';
    }
echo '<li><a href="index.php?sid=' . $sid . '&amp;' . $linklabel . '" title="' . $linklabel . '"' . $active . '>' . $linklabel . '</a></li>';
}
mysqli_free_result($query);	
}

Working :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.