I want that when the database will add a record my window automatically displays the new records. What's missing? index.html ======== <script language="javascript" src="ajax.js"></script> <script language="javascript"> http = getXMLHTTPRequest(); function generalista(){ var myurl = 'cliente_lista.php'; myRand= parseInt(Math.random()*99999999999999999); var modurl = myurl + "?rand=" + myRand; http.open("GET", modurl, true); http.onreadystatechange = useHTTPResponse; http.send(null); } function useHTTPResponse() { if (http.readyState == 4) { if(http.status == 200) { var miTexto = http.responseText; document.getElementById('listacliente').innerHTML = (miTexto); } } else { document.getElementById('listacliente').innerHTML='<img src="cargando.gif">'; } } </script> <body onLoad="generalista()"> <table width="500" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <div id="listacliente"></div></td> </tr> </table> </body> cliente_lista.php ============ <? $cn=mysql_connect("localhost","user_db","key_bd"); mysql_select_db("data_cliente"); $sql="SELECT * FROM cliente"; $rs=mysql_query($sql); $n=mysql_num_rows($rs); ?> <table width='400' border='1' cellspacing='0' cellpadding='0'> <tr> <td bgcolor= '#FFFFCC'>NOMBRES</td> <td bgcolor= '#FFFFCC'>TELEFONO</td> <td bgcolor= '#FFFFCC'>FICHA</td> <td></td> </tr> <? for($k=0;$k<$n;$k++){ $idcliente = mysql_result($rs,$k,"idcliente"); ?> <tr> <td> <? echo mysql_result($rs,$k,"nombres") ?> </td> <td> <? echo mysql_result($rs,$k,"telefono") ?> </td> <td> <img src="explorar.jpg"/></a></td> </tr> <? } ?> </table> Thats all my code.
Do you want your page reloaded when somebody else insert a row in your db? Well, that is almost impossible. Because HTTP events come from the client, not the server. Let alone PUSH and other mechanism available for a small group of client/servers under certain circumstances. You can us a poll strategy instead. You can setup a timer in javascript which will reload table information via AJAX and update your HTML page.
Create a page which list the information and put a meta refresh on it: http://en.wikipedia.org/wiki/Meta_refresh
You can put your AJAX request inside a timer. Use setInterval() javascript function for dispatching the request over a certain period of time.