Luciano Luciano - 1 month ago 8
PHP Question

how to update an include php without refresh in all page

I need update only a part of the page where its included an include php with a specific path. How update only this file included with this include.

Code is this:

<tbody>
<?php include_once "tabelas/table.php"; ?>
</tbody>


What I am doing in really is calling a function javascript that do update and it do update, but it not do update in this include php. Thanks advance!

(i dont want do require in ajax because it is a datatable and in this case it just work with include php, so i need a solution in php preferenly)

Answer

You cannot update only part of a page with PHP without using AJAX. The Javascript AJAX call will run a PHP script that can access the database using PHP and will return the results.

You will need a Javascript function to make the AJAX call:

<script>
function jsupdate(returnid) {
 xmlhttp=new XMLHttpRequest();
 xmlhttp.onreadystatechange=function()  {
 if (xmlhttp.readyState==4 && xmlhttp.status==200) {
    document.getElementById(returnid).innerHTML=xmlhttp.responseText;
 }
}
xmlhttp.open("GET","databasecall.php,true);
xmlhttp.send();

}

Then you will need a PHP script called "databasecall.php that accesses the database, so would contain something like:

//first include your database connection

 $sql = "SELECT * from mytable limit 1 ";
 $result = mysql_query($sql) or die ('Error: XXX000');
 if (mysql_num_rows($result) > 0) {
  $row = mysql_fetch_array($result);
  echo $row[0];
 }
 else {
   echo 'No such database table entry';
 }

The echo-ed results are returned to the Javascript.

Comments