donglvlao8367 2016-02-26 07:57
浏览 123
已采纳

如何在动态while循环中使用活动的锚标记颜色?使用php和mysql

Here is my TableThe table consist of three rows school, college,corporate with primary key and unique id 1,2,3

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,

  • 写回答

2条回答 默认 最新

  • dscqrkvr9562034621 2016-02-26 08:29
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备