javascript - ajax php get row values -


how can value of rows every time clicked correspondent button heres code form

      <form action="<?php echo $_server["php_self"];?>" method="post">           <tbody>               <?php               while ($reserve=mysqli_fetch_array($record)) {                 echo "<tr>";                 echo "<td>".$reserve['id']."</td>";                 echo "<td>".$reserve['room']."</td>";                 echo "<td>".$reserve['status']."</td>";                 echo "<td>".$reserve['client']."</td>";                 echo "<td>".$reserve['dateandtime']."</td>";                 echo "<td>₱ ".$reserve['balance']."</td>";                 echo "<td>".$reserve['additional']."</td>";                ?>                   <td style="text-align: center;">                      <div class="ui buttons">                       <button type="submit" name="approved" class="huge ui green button" id="update">approved</button>                       <button type="submit" name="cancel" class="huge ui red button">cancel</button>                       <button type="submit" name="checkin" class="huge ui teal button">check in</button>                       <button type="submit" name="checkout" class="huge ui violet button">check out</button>                     </div>                   </td>                </tr>           <?php } ?>           </tbody> 

what want value of rows every time clicked correspondent button can update it

try this: add attribute reserveid update button , use jquery script id per current row when click on update button.

      <tbody>           <?php           while ($reserve=mysqli_fetch_array($record)) {             echo "<tr>";             echo "<td>".$reserve['id']."</td>";             echo "<td>".$reserve['room']."</td>";             echo "<td>".$reserve['status']."</td>";             echo "<td>".$reserve['client']."</td>";             echo "<td>".$reserve['dateandtime']."</td>";             echo "<td>₱ ".$reserve['balance']."</td>";             echo "<td>".$reserve['additional']."</td>";            ?>               <td style="text-align: center;">                  <div class="ui buttons">                   <button type="submit" reserveid="<?=$reserve['id']?>"  name="approved" class="huge ui green button" id="update">approved</button>                   <button type="submit" name="cancel" class="huge ui red button">cancel</button>                   <button type="submit" name="checkin" class="huge ui teal button">check in</button>                   <button type="submit" name="checkout" class="huge ui violet button">check out</button>                 </div>               </td>            </tr>       <?php } ?>       </tbody>   <script type="text/javascript">     $(document).on('click', "#update", function(e){         e.preventdefault();          var reserve_id = $(this).attr('reserveid');         alert( 'your reserve_id is: '+ reserve_id);           jquery.ajax({             type : "post",             datatype : "json",             url : 'your-file.php',             statuscode: {                  500: function() {                  alert(" 500 data still loading");                  console.log('500 ');              }         },          data : { reserve_id : reserve_id, action: 'update'},          error: function(xhr, status, error) {             var err = eval("(" + xhr.responsetext + ")");             alert(err.message);         },         success: function(response) {             alert(response.res_message);             },       });      }); </script> 

your-file.php

<?php     if ( isset($_post['action']) ) {          if ($_post['action'] == 'update')         {             $reserve_id = $_post['reserve_id'];             #update code here              $data['res_message'] == "record updated id: $reserve_id";         }         else         {             #code action example delete             $data['res_message'] == "invalid request";         }          echo json_encode($data); die();      }     else     {         $data['res_message'] == "invalid action request";         echo json_encode($data); die();     } ?> 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -