Apologies for the unclear title, my situation is a bit complex and I'm struggling to explain it correctly.
The scenario is illustrated with an image.
1.) I have a while loop processing JSON data from PHP (which includes multiple user IDs). 2.) Ajax retrieves this data and inserts it into HTML with a button assigned to each ID. 3.) When the button is clicked, it sends that specific ID to another PHP script.
I need help on how to extract data[i].userid and data[i].listingid in Ajax and send them out. Thank you for your assistance.
Image
PHP Code Snippet:
$result = mysqli_query($con, "SELECT * FROM list WHERE Listingid = '$Listingid' AND Status ='Bird'");
while($row = mysqli_fetch_array($result)) {
$output[] = $row;
}
if (!empty($output)) {
echo json_encode($output);
} else {
echo json_encode([]);
}
Javascript Code Snippet:
<script>
function gup( name ) {
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if(results == null)
return null;
else
return results[1];
}
var frank_param1 = gup('Listingid');
$("#display12").append(frank_param1);
console.log(frank_param1);
$.ajax({
type: "POST",
url: "list.php",
data: {"data": frank_param1},
dataType:'json',
success: function(data) {
for(var i = 0; i < data.length; i++) {
console.log(data);
var html1 = "<div class=two> Listingid : " + data[i].Listingid + "User id : " + data[i].userid + "</div>" +
"<a id=newListing class=btn btn-success btn-lg1 type=button style=width:140px; href=#noteform data-toggle=modal>" + "submit " + "</a>";
$('#display12').append(html1);
}
}
});
</script>