Elvin Varghese
Elvin Varghese

Reputation: 75

CSS class not getting reflected in the table

I have values in table on which upon click I want to set a particular class and navigate to a certain page. The table looks like this:

    <?php
// Form the page file name
if($content_type == "")  {
    $content_type = "wtc";  
}
?>

<table border='0' width='250' class='navigation'>
    <tr>
        <td align='left' valign='right' class=<?php if($content_type == "wtc") echo 'active'; ?>><a href='?page=wtc'>Create WTC Server</a></td>
    </tr>
    <tr>
        <td align='left' valign='right' class=<?php if($content_type == "rap") echo 'active'; ?>><a href='?page=rap'>Create RAP</a></td>
    </tr>
    <tr>
        <td align='left' valign='right' class=<?php if($content_type == "lap") echo 'active'; ?>><a href='?page=lap'>Create LAP</a></td>
    </tr>
    <tr>
        <td align='left' valign='right' class=<?php if($content_type == "import") echo 'active'; ?>><a href='?page=import'>Import Services</a></td>
    </tr>
    <tr>
        <td align='left' valign='right' class=<?php if($content_type == "export") echo 'active'; ?>><a href='?page=export'>Export Services</a></td>
    </tr>
</table>

Here the thing is it is navigating to another page but the class is not set on the value when it is clicked on.

Please suggest a solution. Thanks in advance.

Upvotes: 0

Views: 85

Answers (1)

Fabrizio Calderan
Fabrizio Calderan

Reputation: 123397

you need to look before at the page value into the $_GET array

// read page parameter (if it exists)
$content_type = @$_GET['page'];

// it's better to always sanitize a bit any user input
$content_type = htmlspecialchars($content_type);

if ($content_type == "")  {
    $content_type = "wtc";  
}

since when you click you're actually passing the page parameter by the querystring

Upvotes: 2

Related Questions