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条)

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示