Skip to content
PHP Logo

How can PHP developers ensure that SQL query results are displayed within a specific <div> container on a webpage?

To ensure that SQL query results are displayed within a specific <div> container on a webpage, PHP developers can use AJAX to fetch the data from the server and then dynamically update the content of the <div> container with the results.

php
<?php
// PHP code to fetch SQL query results
// Assuming $result contains the SQL query results

echo '<script>';
echo 'var xhr = new XMLHttpRequest();';
echo 'xhr.onreadystatechange = function() {';
echo 'if (this.readyState == 4 && this.status == 200) {';
echo 'document.getElementById("your_div_id").innerHTML = this.responseText;';
echo '}';
echo '};';
echo 'xhr.open("GET", "your_php_file.php?data=" . json_encode($result), true);';
echo 'xhr.send();';
echo '</script>';
?>