I've searched this site for the answer that fits this scenario but couldn't.
Here's the Function which returns results from the database of all the users:
function management_active() {
include('db.php');
include('connect.php');
$result = mysqli_query($con,"SELECT * FROM $table_name WHERE activ_status='1'");
while($row = mysqli_fetch_array($result)) {
echo '<tr>';
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['username'] . '</td>';
echo '<td>' . $row['email'] . '</td>';
echo '<td>';
echo '<a href="javascript:;" onclick="showAjaxModal();" class="btn btn-primary btn-xs" data-toggle="tooltip" data-placement="top" title="" data-original-title="View Profile"><i class="fa fa-eye"></i></a>';
echo '<a href="javascript:;" onclick="editAjaxModal();" class="btn btn-primary btn-xs" data-toggle="tooltip" data-placement="top" title="" data-original-title="Edit User"><i class="fa fa-cogs"></i></a>';
echo '<a href="javascript:;" onclick="delAjaxModal();" class="btn btn-primary btn-xs" data-toggle="tooltip" data-placement="top" title="" data-original-title="Remove User"><i class="fa fa-trash"></i></a>';
echo '</td>';
echo '</tr>';
global $user_link;
$user_link = $row['activ_key'];
}
}
This function displays all of the users that are active in a table, I then have buttons which allow a user to view the user's profiles in a modal. The modal needs to load the user's data via AJAX.
Here's the JQUERY Script at the bottom of the page:
<script type="text/javascript">
function showAjaxModal()
{
jQuery('#show-modal').modal('show', {backdrop: 'static'});
setTimeout(function()
{
jQuery.ajax({
url: "data/ajax-profile.php",
data: "u=<?php echo $key; ?>",
success: function(response)
{
jQuery('#show-modal .modal-body').html(response);
}
});
}, 800);
}
</script>
And here's the PHP file which returns the results to the AJAX Call:
$user_link = $_GET['u'];
if ($user_link==="$user_link") {
$result = mysqli_query($con,"SELECT * FROM $table_name WHERE activ_key='$user_link'");
while($row = mysqli_fetch_array($result)) {
echo $row['username'];
echo $row['fname'];
echo $row['lname'];
}
} else {
echo '
<div class="alert alert-danger">
<button type="button" class="close" data-dismiss="alert">
<span aria-hidden="true">×</span>
<span class="sr-only">Close</span>
</button>
<strong>Oh Snap!</strong> Something went terribly wrong.
</div>
';
}
The issue is that I can't seem to get the correct user's details, it always outputs the very last row in the database table.