Od trzech dni staram się stworzyć taki plik generujący dobry xml - bo przypuszczam, że to w nim leży cały mój problem.
<?
header("Content-type: text/xml; charset=windows-1250"); echo '<?xml version="1.0" encoding="UTF-8"?>'; include("mysql.php");
pol_mysql();
$query = mysql_query("SELECT * FROM tabela WHERE id_uzytkownika=1 LIMIT 0,10"); echo '<records total="' . $total . '" count="10" max_per_page="10" page="0">'; echo '<name>'.$row[2].'</name>'; // echo '<surname>'.$row[1].'</surname>';
echo '<telephone>'.$row[3].'</telephone>'; }
?>
Rekordy wyświetla tylko w pliku 2.php(w docelowym 2.html nic nie wyświetla) - wiele razy próbowałem wykombinować z tego kawałka kodu jaka ma być ta zmienna co do sortowania i jak ma być wstawiana. Bezskutecznie.
var currentPage = 0;
var currentSort = "";
var currentSortOrder = "ASC";
var maxPage;
var defaultTableData;
function $(id) {
return document.getElementById(id);
}
function parseRecords(xml) {
with (xml.getElementsByTagName("records").item(0)) {
page = getAttribute("page")*1;
maxPerPage = getAttribute("max_per_page");
startId = maxPerPage*page+1;
total = getAttribute("total")*1;
maxPage = Math.ceil(total/maxPerPage);
$("dataStats").innerHTML =
"Rekordy: " + startId + " - " + (startId+getAttribute("count")*1-1) + " z " + total + " (Strona: " +
(page+1) + " z " + maxPage + ")";
}
$("btnFirst").style.visibility = $("btnPrev").style.visibility = page == 0 ? "hidden" : "visible";
$("btnLast").style.visibility = $("btnNext").style.visibility = page+1 == maxPage ? "hidden" : "visible";
d = $("dataTable");
for (i = d.rows.length-1; i >= 0; i--)
d.deleteRow(i);
record = xml.getElementsByTagName("record");
result = "";
for (i = 0; i < record.length; i++) {
tr = document.createElement("tr");
td = document.createElement("td");
td.innerHTML = startId + i;
tr.appendChild(td);
for (j = 0; j < 3; j++) {
td = document.createElement("td");
td.innerHTML = record[i].childNodes[j].childNodes[0].nodeValue;
tr.appendChild(td);
}
d.appendChild(tr);
}
return result;
}
function getRecords() {
advAJAX.get({
url : "2.php"
onInitialization : function() {
$("dataStats").innerHTML = '<span style="font-weight: bold">Pobieranie danych...
</span>';
$("btnPrev").style.visibility = "hidden";
$("btnNext").style.visibility = "hidden";
$("btnFirst").style.visibility = "hidden";
$("btnLast").style.visibility = "hidden";
},
onSuccess : function(obj) {
parseRecords(obj.responseXML);
}
});
}
function changeSort(s) {
if (currentSort == s)
currentSortOrder = currentSortOrder == "ASC" ? "DESC" : "ASC"; else {
currentSortOrder = "ASC";
if (currentSort != "")
$(currentSort + "Sort").style.fontWeight = "normal";
$(s + "Sort").style.fontWeight = "bold";
}
currentSort = s;
changePage(0);
}
function changePage(p) {
currentPage += p;
getRecords();
}
function initDynamicTable() {
changeSort("surname");
}
Bo najbardziej zależy mi na sortowaniu. Mógłby ktoś pomóc przy tych zmiennych - w wortalu.php.pl też nie jest ten przykład opisany. Przykładów ze strony głównej AdvAJAX od dłuższego czasu nie da się pobrać