duanhai4046 2016-10-06 23:54 采纳率: 100%
浏览 9
已采纳

根据单元格db状态禁用按钮

My code is not working. I'm trying to disable a button based on data from a table cell. This is an example of my table.

 Table A (tickets)
*----------------*
| id | repair_id |
|  1 |  10, 11   |
|  2 |    12     |
*----------------*

and my current code:

<?php
    $sql =  "SELECT repair_id FROM tickets WHERE t_id =".$ticket_id." ";
    $sql .= "AND repair_id REGEXP ',' ";

        $box_check = mysqli_query($connection, $sql);
        $box_empty = mysqli_fetch_array($box_check);
            if(count($box_empty) == 0) {
                echo "<button class='btn btn-primary' disabled='disabled' name='add_box'>Add Box</button>";
            } else {
                echo "<button class='btn btn-primary' type='submit' name='add_box'>Add Box</button>";
            }
?>

My goal is to allow the box to be active so long as there is more than 1 id in repair_id.

Currently the box is disabled or enabled on all depending on if I set if(count($box_empty) == true/false/0/1).

  • 写回答

1条回答 默认 最新

  • dragonpeng200811111 2016-10-07 00:18
    关注

    Right now, ... REGEXP ', ' selects only those rows that have more than one repair ids. Based on your question,

    My goal is to allow the box to be active so long as there is more than 1 id in repair_id.

    Use a simple SELECT query without REGEX and make use of strpos() function to check whether the repair_id column contains more than one repair ids or not, and then display the buttons accordingly, like this:

    $sql =  "SELECT repair_id FROM tickets WHERE t_id =".$ticket_id;
    
    $result = mysqli_query($connection, $sql);
    while($row = mysqli_fetch_array($result)){
        if(strpos($row['repair_id'], ",") === false) {
            echo "<button class='btn btn-primary' disabled='disabled' name='add_box'>Add Box</button>";
        } else {
            echo "<button class='btn btn-primary' type='submit' name='add_box'>Add Box</button>";
        } 
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题