doupai6875 2014-05-09 06:54
浏览 118
已采纳

动态更改表中的行字体颜色

I have a database table named weather which has the following data as below :

Place       Temperature

Delhi          30
Bangalore      35
Hyderabad      45
Mumbai         41

Now I fetch these data using php and view them to the client in a table.

Now my question how can I dynamically change row font color based on value i.e the temperature. Shall I have to put the function in server side or in client side using javascript.

I have applied the logic in this manner but have not reached the destination.

//here is my logic that i have put in my php file while fetching the data
if (row["Temperature"] > row["MaxTemperature"]){
    this.getStyle().color= "red"; }
    else{
    this.getStyle().color="yellow";}
   //I have set a value for MaximumTemperate 
  • 写回答

5条回答 默认 最新

  • douduan2272 2014-05-09 07:01
    关注

    I would do this by creating several css classes, ie:

    <style>
    .red_temperature {
    color: red;
    }
    
    .yellow_temperature {
    color:yellow;
    }
    </style>
    

    then in your php, when you generate your client-side code, you add the class to the class="" of the div holding the values you're displaying to the client.

    ie:

    <?php
    // set $classColor variable here based on mysql row
    ...
    
    echo "<div class='".$classColor."'>74</div>"; // where $classColor = 'yellow_temperature'
    ?>
    

    This is meant to be a generic starting point, not final code, but just trying to point you in the right direction with the right frame of thinking.

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

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建