普通网友 2016-09-23 14:42
浏览 69

区分桌子上的多个按钮。 HTML php

I am creating an edit edit/delete user table and have created an 'edit' button for each record populated in the table. I want to do several things. 1. when an edit button is pressed for a specific user, open a new page called "EDIT." 2. populate form controls in the "EDIT" page with the corresponding user information for the specific 'edit' button that was pressed.

My question is, how do I differentiate between which button is pressed on the users table?

this is what my table looks like:

enter image description here

And this is the code for generating the table and buttons.

if (!$_REQUEST['search']) {

  $sql = "SELECT * FROM users_table ORDER BY lname ASC";

  $retvalues = mysqli_query($conn, $sql);

  $counter = 1;

  while ($row = mysqli_fetch_array($retvalues, MYSQL_ASSOC)) {

    $lname = capword($row['lname']);
    $fname = capword($row['fname']);

    if ($row['admin'] != 1) {
      $stringAdmin = "No";
      $admincolor = "<td>";

    } else {
      $stringAdmin = "Yes";
      $admincolor = "<td style='color:red;'>";
    }
    echo "<tr>";
    echo "<td>".$counter.".</td>";
    echo "<td>".$lname." , ".$fname."</td>";
    echo "<td>".$row['email']."</td>";
    echo "<td>".$row['password']."</td>";
    echo $admincolor.$stringAdmin."</td>";
    echo "<td><input type='checkbox' name='user[]' value='{$row['id']}'></td>";
    echo "<td><input type='submit' name='edit' value='edit'></td>";
    echo "</tr>";

    $counter++;
  }
}
  • 写回答

5条回答 默认 最新

  • douchun9719 2016-09-23 15:01
    关注

    You can differentiate the each edit button by using unique id

    <button class='edit' data-id="<?php echo $_GET["id"];?>"> EDIT</button>.
    

    While click on the edit button, read the data-id by using the following code

    $(document).on('click', '.edit', function(){
      var id = $(this).attr('data-id');
     //code - you need to do
    })
    

    Better to show the data on next page, use bootstrap model box and AJAX request which will interact lot of the users.

     $(document).on('click', '.edit', function(){
        var id = $(this).attr('data-id');
        if(id) {
            $.ajax({
                url : your url("profile/edit/"+id)
                type : 'post',
                success: function(response){
                    if (response.success) {
                        $('#modal').modal('show');
                    }
                }
            }):
        }
    });     
    
    评论

报告相同问题?