Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Hiding a button dependant on cell value in table

I currently have a table that data is being reported into with a few buttons at the end to perform actions (Consign, Unconsign, Edit, Delete). I’m trying to hide the Consign and Unconsign buttons for each row in the table depending on the Yes/No value a column.

So far, I’ve managed to get the button Consign to hide if the consigned cell is Yes. The problem is that for cells returning No, the Consign button is still hidden and the Unconsign button still shows. What would be the best way to fix this?

Here is the code and example so far.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<thead>
     <tr>
       <th data-checkbox="true"></th>
       <th data-field="no" data-sortable="true" data-sorter="dateSorter" data-visible="false">No</th>
       <th data-field="location" data-sortable="true" data-filter-control="select" data-filter-control-placeholder="Select Location">Location</th>
       <th data-field="name" data-visible="false">Name</th> 
       <th data-field="area" data-visible="false">Area</th>
       <th data-field="sendto" data-visible="false">Send To</th>        
       <th data-field="reference">Reference</th>
       <th data-field="consigned" data-filter-control="select" data-filter-default="No">Consigned</th>
       <th data-field="date_consigned" data-visible="false">Date Consigned</th>
       <th data-field="action" class="col-lg-2">Action</th>
     </tr>
</thead>
<tbody> 
<?php

        if ($result->num_rows > 0) {
            while($row = $result->fetch_assoc()) {
              echo '<tr>';
              echo '<td></td>';             
              echo '<td>'.$row["no"].'</td>';
              echo '<td>'.$row["location"].'</td>';
              echo '<td>'.$row["name"].'</td>'; 
              echo '<td>'.$row["area"].'</td>';     
              echo '<td>'.$row["sendto"].'</td>';
              echo '<td>'.$row["reference"].'</td>';
              echo '<td>'.$row["consigned"].'</td>';
              echo '<td>'.$row["date_consigned"].'</td>';
                if ($value['consigned'] != 'Yes') {
              echo "<td>
                        <a href='#consign_".$row['no']."' class='btn btn-warning btn-sm hide' data-toggle='modal' id='consign' name='consign'><span class='glyphicon glyphicon-check'></span> Consign</a>
                        <a href='#unconsign_".$row['no']."' class='btn btn-warning btn-sm' data-toggle='modal' id='unconsign' name='unconsign'><span class='glyphicon glyphicon-check'></span> Unconsign</a>                            
                        <a href='#edit_".$row['no']."' class='btn btn-success btn-sm' data-toggle='modal'><span class='glyphicon glyphicon-edit'></span> Edit</a>
                        <a href='#delete_".$row['no']."' class='btn btn-danger btn-sm' data-toggle='modal'><span class='glyphicon glyphicon-trash'></span> Delete</a>
                    </td>";
                } else {
              echo "<td>
                        <a href='#consign_".$row['no']."' class='btn btn-warning btn-sm' data-toggle='modal' id='consign' name='consign'><span class='glyphicon glyphicon-check'></span> Consign</a>
                        <a href='#unconsign_".$row['no']."' class='btn btn-warning btn-sm hide' data-toggle='modal' id='unconsign' name='unconsign'><span class='glyphicon glyphicon-check'></span> Unconsign</a>                           
                        <a href='#edit_".$row['no']."' class='btn btn-success btn-sm' data-toggle='modal'><span class='glyphicon glyphicon-edit'></span> Edit</a>
                        <a href='#delete_".$row['no']."' class='btn btn-danger btn-sm' data-toggle='modal'><span class='glyphicon glyphicon-trash'></span> Delete</a>
                    </td>";
                }
              echo "</tr>";
                include('edit-delete-modal.php');
              echo "</tr>";
            }
          }
?>

Image of table buttons

>Solution :

I found something in your logic (if statement)

 if ($value['consigned'] != 'Yes') { // true when $value['consigned'] is No
          echo "<td>
                    <a href='#consign_".$row['no']."' class='btn btn-warning btn-sm hide' data-toggle='modal' id='consign' name='consign'><span class='glyphicon glyphicon-check'></span> Consign</a>
                    <a href='#unconsign_".$row['no']."' class='btn btn-warning btn-sm' data-toggle='modal' id='unconsign' name='unconsign'><span class='glyphicon glyphicon-check'></span> Unconsign</a>                            
                    <a href='#edit_".$row['no']."' class='btn btn-success btn-sm' data-toggle='modal'><span class='glyphicon glyphicon-edit'></span> Edit</a>
                    <a href='#delete_".$row['no']."' class='btn btn-danger btn-sm' data-toggle='modal'><span class='glyphicon glyphicon-trash'></span> Delete</a>
                </td>";
            } else {
          echo "<td>
                    <a href='#consign_".$row['no']."' class='btn btn-warning btn-sm' data-toggle='modal' id='consign' name='consign'><span class='glyphicon glyphicon-check'></span> Consign</a>
                    <a href='#unconsign_".$row['no']."' class='btn btn-warning btn-sm hide' data-toggle='modal' id='unconsign' name='unconsign'><span class='glyphicon glyphicon-check'></span> Unconsign</a>                           
                    <a href='#edit_".$row['no']."' class='btn btn-success btn-sm' data-toggle='modal'><span class='glyphicon glyphicon-edit'></span> Edit</a>
                    <a href='#delete_".$row['no']."' class='btn btn-danger btn-sm' data-toggle='modal'><span class='glyphicon glyphicon-trash'></span> Delete</a>
                </td>";
            }
          echo "</tr>";
            include('edit-delete-modal.php');
          echo "</tr>";
        }

Suggest:

modify if statement

$value['consigned'] == 'Yes'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading