Home > database >  PHP checkbox only showing first value
PHP checkbox only showing first value

Time:08-22

I am trying to iterate the row data of each message for each value in the database by a checkbox as when clicked you get the string value on this row

the Code:

  <div id="Ticket" style="display:none;" >
    <table >
    <thead>
        <tr>
            <th>Ticket ID </th>
            <th>username</th>
            <th>Data published</th>
            <th>Subject</th>
            <th>problem</th>
            <th>Statues</th>
            <th>Solved?</th>
            <th>More Details</th>
            
        </tr>
    </thead>
    <tbody>
        <?php
        $query=" Select * FROM tickets where resolved=0";
        $result_opened = mysqli_query($db, $query);
                    while($row = mysqli_fetch_array($result_opened)){ ?>


        <tr>
            <td data-label="id"><?php echo $row['id']?></td>
            <td data-label="username"><?php echo $row['username']?></td>
            <td data-label="publish"><?php echo $row['published']?></td>
            <td data-label="subject"><?php echo $row['subject']?></td>
            <td data-label="problem"><?php echo $row['problem']?></td>
            <td data-label=""><a href="#" >Open</a></td>
         <td>    <a href="resolve.php?id=<?php echo $row['id']?>"  ><i ></i> </a> <br/><br/>
                    </td> 
<td><input type="checkbox" id="toggle">
   <label for="toggle">see more</label>

   <dialog >
    <h>Message</h><br><br>
      <p>
   //Here I am getting only the first value//
    <?php echo $row['message'] ?>
     </p>


    <label for="toggle">close</label>
    </dialog></td></tr>
                    <?php }?>
      </tbody>
  </table>
     </div>
   

but I keep on getting only the last value in the specific row

image:

I tried many ways to fix it but the main problem is its only getting the first value in the while loop.

CodePudding user response:

The problem arises because you are assigning same id to all checkbox component.

Instead use this -

input type="checkbox" id="toggle-<?=$row['id']?>">
  • Related