You can easily achieve this by preparing a application/json
response and sending back to the jQuery
(presume that's what you use).
First you will need to prepare your data array. To do that, you will need to iterate through the query results, like this.
$dataArray = array();
foreach ($result1 as $row) {
$dataArray [] = $row;
}
At this point you will have the array loaded with data. Then all you need to do is send back as a application/json
response.
header('Content-Type: application/json');
echo json_encode($dataArray);
The calling jQuery
function will look like this,
$(document).ready(function(){
$("button").click(function(){
$.ajax({url: "submit.php", success: function(result){
console.log(result);
}});
});
});
The above console.log
line will dump you the response came from the PHP
and it will look like this.
{ name: "Test Name", description: "Test Desription", date: "22/10/2018"}
Please note that above data is based on the following data array. Only for the demonstration purposes.
array('name' => 'Test Name', 'description' => 'Test Desription', 'date' => '22/10/2018');
I hope this helps,
Cheers.