首先描述情況。我的索引頁面被分爲兩個div區域,我的新聞文章顯示在這裏。剩下的每個部分都有一個分頁,所以用戶不需要刷新頁面。 一切工作與我的舊代碼,現在我將這些舊代碼更改爲PHP Pdo,以防止SQL注入。攻擊螞蟻來更新我自己:)php pdo with js分頁
基本上一切都很順利,直到現在。也許它太晚或是別的什麼,這應該是simpe解決方案,因爲我已經在我的左側工作解決方案。差異僅在於選擇應選擇文本的字符和類別名稱。 這裏是代碼: 工作代碼,頁面
$offset = ($pageNum - 1) * $rowsPerPage;
$selectString = '%News-BlockLeft%';
$STH = $DBH->prepare("SELECT ... " .
"FROM News, Categories, NewsCheck " .
"WHERE Name LIKE :selectString " .
"ORDER BY `NewsDate` DESC LIMIT :offset, :rowsPerPage");
$STH->bindParam(':selectString ', $selectString, PDO::PARAM_STR);
$STH->bindParam(':offset', $offset, PDO::PARAM_INT);
$STH->bindParam(':rowsPerPage', $rowsPerPage, PDO::PARAM_INT);
$STH->execute();
這些代碼會火的onclick JS將返回第二頁的左側部分爲遵循
if ($pageNum > 1) {
$opage = $pageNum - 1;
$prev = "<a href=\"javascript:goToPage(" . $opage . ");\"><img src=\"/firstPage.gif\" /> </a>";
$first = "<a href=\"javascript:goToPage(" . $opage . ");\">[<<]</a>";
} else {
$prev = ''; // we're on page one, don't enable 'previous' link
$first = ' <font size=\"3\">[<<] </font>'; // nor 'first page' link
}
ajaxRequest.js
function goToPage(page) {
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null) {
alert ("Your browser does not support AJAX!");
return;
}
var url="myPageBlockLeft.php";
url=url+"?opage="+page;
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete") {
document.getElementById('contentRight').innerHTML=xmlhttp.responseText;
initLightbox();
}
}
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
選擇字符串幾乎相同,在工作的左側我選擇
WHERE Name LIKE :selectString
,並在其不工作,我需要選擇Where Name=:selectString
希望問題不健全太糊塗了,因爲我累了,如果你需要更多的信息,請詢問對方。