duanmengmiezen8855 2016-09-12 19:51
浏览 22
已采纳

检查下拉列表并动态更改单元格颜色

I have a web table displaying a sql server database table using php pdo. The table is created and displayed on index.php file. I have a form in edit.php where users can update the table. Some of the fields in edit.php have dropdowns. For example, one field has dropdown options Q1,Q2,Q3,and Q4. If the initial value is Q1 or the user updates to Q1, I want to make the background color of the cell in table to be green, if Q2=>yellow, Q3=>red. Can somebody please help me with this? I have index.php and edit.php shown below:

index.php

<?php
require_once('include/database.php');
?>

<!DOCTYPE html>
<html>
<head>     </head>
<body>
<tr><th>Q Rating</th></tr>
<tr><th>Action</th></tr>

<?php
        $stmt = $conn->prepare("SELECT * FROM MATRIX ORDER BY OBJECTID ASC");
        $stmt ->execute();
        $result = $stmt->fetchAll();
        foreach($result as $row) {

        ?>

    <tr>
    <td><?=$row['Q_Rating'];?></td>
    <td><a href="edit.php?id=<?=$row['OBJECTID'];?>">Edit </a>  </td>

Edit.php

   <form action="" method="post"> 
    <tr>
                <td>ATFP</td>
                <td><label>
                        <select name="txt_qrating" class="textfields"           id="q_rating">
                            <option id="0">Select One</option>
                            <option id="1"> Q1</option>
                            <option id="2">Q2</option>
                            <option id="3">Q3</option>
                            <option id="4">Q4</option>

                        </select>
                     </label>
                </td>
            </tr>

            <tr>
                <td><label>
                        <input type="hidden" name="txt_id" value="<?= $object_id; ?>">
                    </label>
                </td>
                <td><label><input type="submit" name="btn_submit" value="Submit">
                    </label>
                </td>
            </tr>
  • 写回答

1条回答 默认 最新

  • duanrang9348 2016-09-12 20:19
    关注

    Simply add some css style with proper classes:

    .green { color: green;} .red { color: red;}
    

    .. then add some inline conditionals like:

    <table>
    <tbody><tr>
    <td class="<?php echo ("quatity1" === $myvar ? 'red' : 'green'; ?>">tdValueHere</td>
    </tr></tbody></table>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c