0
나는이 작업을하기 위해 며칠을 보냈습니다. 책 데이터베이스가 있습니다. getBooks라는 함수 파일이 있습니다.복잡한 쿼리에 페이지 매기기 추가
function getBooks($limit = 10000, $sortBy = 'tblAuthor.LastName' , $direction='ASC', $where=1){
$db = connect();
$fields = array('tblBook.Title', 'tblAuthor.FirstName', 'tblAuthor.LastName', 'tblCategory.Category');
$format = 'Select '. implode(', ', $fields) .' FROM tblAuthor INNER JOIN (tblBook INNER JOIN tblCategory ON tblBook.CatID=tblCategory.CatID) ON tblBook.AuthorID=tblAuthor.AuthorID where %1$s ORDER BY %2$s %3$s LIMIT %4$s ';
$query = sprintf($format, $where, $sortBy, $direction, $limit);
$escapedQuery = stripslashes($db->realEscape($query));
$db->runQuery($escapedQuery);
if($db->hasErrors()){
print_r($db->getErrors());
echo('<br /><br />Exiting the script.');
die();
}
$results = $db->fillResultset();
close($db);
return $results;
} // 끝 getbooks ?> 다음의 나머지 부분을 처리하는 라이브러리라고
.
<?php
// include header
include ("header.php");
include_once('bookFunctions.php');
$books=getBooks();
$myName = "My Books";
?>
<div id="content">
<?php if (count($books)){
?>
<table class="books">
<tr>
<th>Book Title</th>
<th>Author's Last Name</th>
<th>Author's First Name</th>
<th>Genre</th>
</tr>
<?php
foreach($books as $book)
{
echo "<tr>";//start the row
//echo out each cell
echo "<td>" . $book['Title'] . "</td>";
echo "<td>" . $book['LastName'] . "</td>";
echo "<td>" . $book['FirstName'] . "</td>";
echo "<td>" . $book['Category'] . "</td>";
echo "</tr>";//end the row
}
?>
나는 매김 스크립트와 tuts의 모든 종류를 시도했지만 난 그냥 내 쿼리에 삽입 할 위치를 알아낼 수 없습니다. 내가 고민하고있는 최신 하나는 다음과 같습니다. http://stefangabos.ro/php-libraries/zebra-pagination/ 이 작업을 수행하는 방법이 있어야합니다. 모든 조언을 부탁드립니다.
그것은 당신처럼 보인다
한 가지 방법은 페이지와 num_per 페이지 PARAMS를 포함하도록 함수 프로토 타입을 수정하는 것입니다 첫 번째 페이지에 대해 'LIMIT start, length', 예를 들어'LIMIT 0,10'과 같은 페이지 매김의 경우에만 한 개의 매개 변수를 제한 -> 전달합니다. 참조 문서는 http://dev.mysql.com/doc/refman/5.5/en/select.html에 있습니다. –
거기에는 제한이 있었으며 데이터베이스 출력을 줄였습니다. 페이지 매김, 페이지가 없습니다. 그래서 원래대로 되돌려 놓았습니다. – Sliloh