我在 PHP 中有表格形式的數據,我需要的是,當兩列的值相同時,必須禁用該特定的按鈕

普魯斯維·莫罕

因此,在下面的代碼中,當列mi_name等於同一行的 item_name 時,必須禁用該行的按鈕。

<?php
    require_once('conn.php');

         $sql_count="SELECT COUNT(mi_number)
         FROM a_items z INNER JOIN m3data_items_all a ON (a.mi_number =z.item_number) 
          where plan_id=11 ";
          $Info_count = mysqli_query($con, $sql_count) or die(mysqli_error());
          $row_Info_count = mysqli_fetch_all($Info_count,MYSQLI_ASSOC);


      $sql_row="SELECT mi_number,item_number, mi_name,item_name,mi_description,item_description,plan_id 
                  FROM a_items z INNER JOIN m3data_items_all a ON (a.mi_number =z.item_number) 
                  where plan_id=11 ";
      $Info_data = mysqli_query($con, $sql_row) or die(mysqli_error());
     //print_r($Info);
      $row_Info_data = mysqli_fetch_all($Info_data,MYSQLI_ASSOC);
     
       echo "<div><h2>Count  : ".$row_Info_count[0]['COUNT(mi_number)']."<h2></div><table border='1px' cellpadding='5px cellspacing='0px'>
       <h1>ALL FETCH  DATA</h1>
       <tr>
       <th>mi_number</th>
       <th>item_number</th>
       <th>mi_name</th>
       <th>item_name</th>
       <th>mi_description</th>
       <th>item_description</th>
       <th>plan_id</th>
       </tr>";
   
        foreach($row_Info_data as $data){
            echo "<tr>
             <td>".$data['mi_number']."</td>
             <td>".$data['item_number']."</td> 
             <td>".$data['mi_name']."</td> 
             <td>".$data['item_name']."</td>
              <td>".$data['mi_description']."</td>
               <td>".$data['item_description']."</td>
            <td>".$data['plan_id']."</td>
            <td><button type=buttton >Compare me!</button></td>
            </tr>";
        }
        echo "</table>";
?>
阿馬爾·阿斯拉姆
foreach($row_Info_data as $data){
            echo "<tr>
             <td>".$data['mi_number']."</td>
             <td>".$data['item_number']."</td> 
             <td>".$data['mi_name']."</td> 
             <td>".$data['item_name']."</td>
              <td>".$data['mi_description']."</td>
               <td>".$data['item_description']."</td>
            <td>".$data['plan_id']."</td>";

            if($data['mi_name'] == $data['item_name']) {
                echo "<td><button type='buttton' class='disabled'>Compare me!</button></td>";
            } else {
                echo "<td><button type='buttton'>Compare me!</button></td>";
            }

            echo "</tr>";
}

這也可以通過較短的版本來實現:

echo "<td><button type='buttton'".($data['mi_name'] == $data['item_name'] ? "class='disabled'" : "").">Compare me!</button></td>";

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章