1

I've a link in admin-dashboard page which on click shows "doctor-details". Now I want the admin must be able to click on the options link in the table and see full details of the doctor in the same page(I'll probably use modals for this).

So my question is how do I get the ID from the table and send it to another php file for database query? table showing minimum details about doctor

my code for generating details about doctor(doctor-details.php)

<?php

require('config.php');
$sql = "SELECT * FROM doctor";
$result = mysqli_query($conn, $sql);

$count = mysqli_num_rows($result);
if($count > 0){
    while($rows = mysqli_fetch_array($result)){

        ?>
        <tr>
            <td><?php echo $rows['id'];?> </td>
            <td><?php echo $rows['f_name'];?></td>
            <td><?php echo $rows['l_name'];?></td>
            <td><?php echo $rows['email'];?></td>
            <td><?php echo $rows['contact_number'];?></td>
            <td><?php echo $rows['gender'];?></td>
            <td><a href=""> Options</a></td>
        </tr>

        <?php


    }
}
?>

and finally my ajax:

$(document).ready(function(){
        $("#load-doctor-data").click(function(){
            $.ajax({
                url: 'views/admin/doctor-details.php', 
                type: 'POST',
                success: function(result){
                    $("#response-doctor").html(result);
                }
            });
        });
    });



    //Hide table on login
    $("#show-doctor-details").hide();

    $(document).ready(function(){
        
        $("#load-doctor-data").click(function(){
            $("#show-doctor-details").show();
            $("#show-patient-details").hide();
          });
    });

So, the gist is I want to click on options and show full details of John Doe.

  • Does this answer your question? [Ajax passing data to php script](https://stackoverflow.com/questions/6782230/ajax-passing-data-to-php-script) – imposterSyndrome Aug 07 '20 at 07:38
  • To some extent. I think now I know how to recieve data on the back end. but I still don't understand how to get ID of "John Doe" by clicking on the options link –  Aug 07 '20 at 08:05

1 Answers1

0

Data attributes are a pretty easy to pass data. So when first appending make sure you have the id in the options field like this:

<td><a href="" class="options" data-id="<?php echo $rows['id'];?>"> Options</a></td>

Now you can get this id in your click event handler like this:

$(document).on('click','.options', function(){
  var currentId = $(this).data('id');
  ...
});

Also you don't need two document readys. You can wrap both event handlers in one document ready.

Wimanicesir
  • 4,606
  • 2
  • 11
  • 30
  • I've removed the unnecessary document readys. But I still don't understand how I'm supposed to use that ID in php to query for the details of the doctor –  Aug 07 '20 at 16:04