Home > Software design >  How to hide table row?
How to hide table row?

Time:05-01

I am trying to hide the table row for user_id. I only want to show the full name, user name, and actions in the table. I tried to remove the code for the user id row, but it affected the other functionalities like the edit and delete.

here is the code:

<form method="post" id="editForm"> 
    <table >
        <tbody>
        <tr>
                <th scope="col">USER ID</th>
                <th scope="col">FULL NAME</th>
                <th scope="col">USER NAME</th>
                <th scope="col">ACTIONS</th>
        </tr>
        
        <?php $a = 0?>

        <?php while ($row = mysqli_fetch_array($res)) { 

            echo "<tr id=".$a  .">
                <th scope='row' class='row-data'>".$row['user_id']."</th>
                <td class='row-data'>".$row['full_name']."</td>
                <td class='row-data'>".$row['user_name']."</td>
                <td><input type='button' 
                        value='EDIT'
                           onclick='editUser()'' /></td>
                <td><input type='button' 
                         value='DELETE' 
                   onclick='deleteUser()' /></td>
            </tr>
        
        </tbody>";
       }; ?>

CodePudding user response:

Instead of removing the column, you can set the display style to 'none' for this column

(add style="display:none;")

Hence (1) change

<th scope="col">USER ID</th>

to

<th scope="col" style="display:none;">USER ID</th>

and (2) change

<th scope='row' class='row-data'>".$row['user_id']."</th>

to

<th scope='row' class='row-data' style="display:none;">".$row['user_id']."</th>

CodePudding user response:

You could try modifying the editUser() and deleteUser() Javascript methods to accept a userId parameter. It would probably clean up some of the code as well on the JS side. Just a suggestion though. That snippet then might look something like this:

<form method="post" id="editForm"> 
    <table >
        <tbody>
        <tr>
                <th scope="col">FULL NAME</th>
                <th scope="col">USER NAME</th>
                <th scope="col">ACTIONS</th>
        </tr>
        
        <?php $a = 0?>

        <?php while ($row = mysqli_fetch_array($res)) { 

            echo "<tr id='".$a  ."'>
                <td class='row-data'>".$row['full_name']."</td>
                <td class='row-data'>".$row['user_name']."</td>
                <td><input type='button' 
                        value='EDIT'
                           onclick='editUser(".$row['user_id'].")'' /></td>
                <td><input type='button' 
                         value='DELETE' 
                   onclick='deleteUser(".$row['user_id'].")' /></td>
            </tr>
        
        </tbody>";
       }; ?>

Otherwise you could use Ken's solution which would probably work with your existing code.

  • Related