I`am trying to get the $row['username'] every time I click on the button, for me to use it in the query . But only the first array is displayed. I want to use jquery but I have small knowledge on it.
<?php
$query = $con->query("SELECT * FROM account WHERE acc = 'agency'");
while($row = mysqli_fetch_array($query))
{
echo $row['username'];
?>
<button data-target="#select" data-toggle="modal">Select</button>
<?php } ?>
<div class="modal" id="select">
<?php
$query = $con->query("SELECT * FROM sample WHERE username = ".$row['username']."");
?>
<button id="select"
class="selectUser"
data-username="<?php echo $row['username']; ?>"
data-toggle="modal"
data-target="#select">Select</button>
I took the html you put in your comment, and added a class to it. Now all you need to do is create your javascript binding for it.
//find all the buttons with the selectUser class and bind a click handler to them
$('.selectUser').on('click', function(e){
//turn the element into a jQuery object so we can use jQuery methods
var $selectUser = $(this);
//log the username data attribute from the button
console.log($selectUser.data('username'));
//you could also get the attribute without jQuery
console.log(this.getAttribute('data-username'));
});