Here is my php code:
<?php
$sql=mysql_query("select * from parent_cat order by pid ");
while($row=mysql_fetch_array($sql))
{
$pid=$row['pid'];
?>
<div class="overallcopt"><a href="index.php?master=<?php echo $row['pid']; ?>"><?php echo $row['p_cat'];?></a></div>
<?php
}
?>
1.If user click school ,school should be in active, I want to highlight school in red color and rest college and corporate should in black color, 2.If user click college ,college should be in active, I want to highlight college in red color and rest school and corporate should in black color, 3. Like wise for corporate,
In PHP, you can add active class on anchar as:
while($row=mysql_fetch_array($sql))
{
$active = (intval($_GET['master']) == $row['pid'] ? 'class="active"' : '');
..........
Use this variable in your HTML:
<a <?=$active?> href="index.php?master=<?php echo $row['pid']; ?>"><?php echo $row['p_cat'];?></a>
Side Note:
Please use mysqli_*
or PDO
instead of mysql_*
its deprecated and not available in PHP 7.
<?php
$sql=mysql_query("select * from parent_cat order by pid ");
while($row=mysql_fetch_array($sql)){
$pid=$row['pid'];
?>
<div class="overallcopt" style="background-color:<?php if(isset($_GET['master']) && $_GET['master']==$row['pid']){echo "red";}else{echo "black";} ?>;"><a href="index.php?master=<?php echo $row['pid']; ?>"><?php echo $row['p_cat'];?></a></div>
<?php
}
?>
Try this