私はこの作業をしようとしました。私は本のデータベースを持っています。私は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/ これを行うには何か方法があるはずです。アドバイスをいただければ幸いです。
それはあなたのように見えます最初のページで 'LIMIT start、length'、例えば' LIMIT 0,10'としたいページングのために、limit - >に1つのパラメータを渡すだけです。リファレンスドキュメントはhttp://dev.mysql.com/doc/refman/5.5/en/select.html –
私はそこに限界があり、データベースの出力をうまく短縮しましたが、どこにページ区切りのものは、ページがありませんでした。だからオリジナルに戻しました。 – Sliloh