Skip to content
Advertisement

I have Data in the form of table in PHP, What i need is that when the two columns are of same value the button for that particular has to be disabled

So in the below code when the column mi_name is equal to the item_name of the SAME ROW, the button of that row has to be disabled.

<?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>";
?>

Advertisement

Answer

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>";
}

This can also be achieved with a shorter version:

echo "<td><button type='buttton'".($data['mi_name'] == $data['item_name'] ? "class='disabled'" : "").">Compare me!</button></td>";
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement