Salve,
vorrei suddividere i risultati di una query mysql in più pagine.
Attualmente sono arrivato a questo punto:
1. Questo è il file responsexml.php
Codice PHP:
$sql="SELECT * FROM commenti WHERE stato='1' && id_video='$id' ORDER BY id DESC";
$result = mysql_query($sql);
$totale = mysql_num_rows($result);
$giorno = array('Domenica', 'Lunedì', 'Martedì', 'Mercoledì', 'Giovedì', 'Venerdì', 'Sabato');
echo '<?xml version="1.0" encoding="ISO-8859-1"?>
<commento>';
echo "<totale>" . $totale . "</totale>";
while($row = mysql_fetch_array($result)){
$row['time'] = $giorno[date("w", $row['time'])].', '.date("d/m/Y h:i:s", $row['time']);
echo "<id>" . $row['id'] . "</id>";
echo "<autore>" . $row['autore'] . "</autore>";
echo "<testo>" . $row['testo'] . "</testo>";
echo "<email>" . $row['email'] . "</email>";
echo "<reply>" . $row['reply'] . "</reply>";
echo "<time>" . $row['time'] . "</time>";
}
echo "</commento>";
mysql_close($con);
2. questo è il file responsexml.js
Codice PHP:
var xmlHttp
function listCommenti(str,id)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="includes/responsexml.php"
url=url+"?id="+id
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
xmlDoc=xmlHttp.responseXML;
var tot = xmlDoc.getElementsByTagName("totale")[0].childNodes[0].nodeValue;
for (i=0; i<tot; i++) {
document.getElementById("id_"+i).innerHTML = xmlDoc.getElementsByTagName("id")[i].childNodes[0].nodeValue;
document.getElementById("autore_"+i).innerHTML = xmlDoc.getElementsByTagName("autore")[i].childNodes[0].nodeValue;
document.getElementById("testo_"+i).innerHTML = xmlDoc.getElementsByTagName("testo")[i].childNodes[0].nodeValue;
document.getElementById("time_"+i).innerHTML = xmlDoc.getElementsByTagName("time")[i].childNodes[0].nodeValue;
}
}
}
function GetXmlHttpObject()
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
tutto questo funziona alla grande ma vorrei suddividere i risultati senza reload della pagina.
Qualche idea?