0

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;" class="tabcontent">
    <table class="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="#" class="btn btn__active">Open</a></td>
         <td>    <a href="resolve.php?id=<?php echo $row['id']?>" class="btn btn-warning" ><i class="fa-solid fa-circle-check"></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.

1
  • 1
    change id="toggle" to id="toggle-<?=$row['id']?>" class="toggle-resolved" in html id field is unique thing, there cannot be many items with same id (which is toggle) and so it takes first one. also <label for="toggle"> to <label for="toggle-<?=$row['id']?>"> Commented Aug 20, 2022 at 17:50

1 Answer 1

1

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

Instead use this -

input type="checkbox" id="toggle-<?=$row['id']?>">
Sign up to request clarification or add additional context in comments.

3 Comments

I tried your solution and it seems logic but something happened with the checkbox and it stopped showing the message link
Check your inspected HTML
Thank you ,it was a css issue as I change the id to toggle-<?=$row['id']?> it stopped taking its respective css so to solve the issue I created a class name for it and it worked fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.