mysql と meekrodb を使用してデータベースから情報を取得するページがあります。結果は、1 ページあたり 15 個と、データベースの英数字サブセットに制限されます。この例では、1-3 & AB
#goleft または #gort のいずれかをクリックしたときにページネーションを追加すると、データベースから正しいアイテムが取得されます。
pagination.php への ajax 呼び出しを呼び出して変数 $start を渡すにはどうすればよいですか? すべてについて確信が持てないので、間違った場所があれば修正してください。pagination.php で $start,15 が正しいかどうかわからない
私はここまで来ました:
メインページ:
<?php
require_once 'meekrodb.2.2.class.php';
require_once 'dconnect.php'; // database login info
// currently pulling $results from database on initial pg load
$results = DB::query("SELECT substr(theme, 1, 1) as Alphabet, theme, developer, thumb, thumb_lg FROM gallery ORDER BY (CASE Alphabet
WHEN '1' THEN 1
WHEN '2' THEN 2
WHEN '3' THEN 3
WHEN 'A' THEN 4
WHEN 'B' THEN 5
ELSE 6
END), theme
LIMIT 15");
// get count of all relevant items
$tcount = DB::query("SELECT substr(theme, 1, 1) as Alphabet, theme, developer, thumb, thumb_lg FROM gallery ORDER BY (CASE Alphabet
WHEN '1' THEN 1
WHEN '2' THEN 2
WHEN '3' THEN 3
WHEN 'A' THEN 4
WHEN 'B' THEN 5
ELSE 6
END), theme");
// get count of all relevant items
$counter = DB::count();
$ipp = 15; // items per page
$tpages = ceil($counter / $ipp); // total pages
// write each entry to specific div;
$x = 0;
foreach ($results as $row) {
$x++;
if ($x == 1) {
$t1 = $row['theme'];
$d1 = $row['developer'];
$th1 = $row['thumb'];
$thlg1 = $row['thumb_lg'];
}
... Additional if's through 15th item
}
?>
Basic Html:
<img src="<?php echo($th1); ?>" data-retina="<?php echo($thlg1); ?>" alt="<?php echo($t1); ?>" />
<span><p class="hname"><?php echo($t1); ?></p>
<div class="bull">•</div>
<p class="hdev"><?php echo($d1); ?></p></span>
...
<div id="thumbnav"><div id="goleft"></div><div id="gort"></div></div>
メイン pg jQuery:
// Previous button
var curpg = 1;
$('#goleft').mouseup (function() {
var newpg = curpg - 1;
if (newpg == 0) {newpg = 1} // reset page if going back to first page
curpg = newpg;
var $start = (newpg - 1) * 15 + 1;
// how to pass $start to pagination.php ??
});
// Next button
$('#gort').mouseup (function() {
var newpg = curpg + 1;
var $totpgs = <?php echo $tpages; ?>; // DOESN'T Echo anything !!!
console.log('Total Pages: ' + $totpgs);
if (newpg > $totpgs) {newpg = $totpgs} // limit page to total pages
curpg = newpg;
var $start = (newpg - 1) * 15 + 1;
console.log('Start: ' + $start);
// how to pass $start to pagination.php ??
});
ページネーション.php:
<?php
require_once 'meekrodb.2.2.class.php';
require_once 'dconnect.php'; // database login info
// pull from database using specific page items
$results = DB::query("SELECT substr(theme, 1, 1) as Alphabet, theme, developer, thumb, thumb_lg FROM gallery ORDER BY (CASE Alphabet
WHEN '1' THEN 1
WHEN '2' THEN 2
WHEN '3' THEN 3
WHEN 'A' THEN 4
WHEN 'B' THEN 5
ELSE 6
END), theme
LIMIT $start,15");
?>
更新 1: Pagination.php
<?php
$start = $_POST['start']; // capture input from AJAX
require_once 'meekrodb.2.2.class.php';
require_once 'dconnect.php';
// pull from database using specific page items
$navresults = DB::query("SELECT substr(theme, 1, 1) as Alphabet, theme, developer, thumb, thumb_lg FROM gallery ORDER BY (CASE Alphabet
WHEN '1' THEN 1
WHEN '2' THEN 2
WHEN '3' THEN 3
WHEN 'A' THEN 4
WHEN 'B' THEN 5
ELSE 6
END), theme
LIMIT $start,15");
$x = 0;
foreach ($navresults as $row) {
$x++;
if ($x == 1) {
$t1 = $row['theme'];
$d1 = $row['developer'];
$th1 = $row['thumb'];
$thlg1 = $row['thumb_lg'];
}
... up to 15th variable set
}
主な jQuery:
//Next pagination
$('#gort').mouseup (function() {
var newpg = curpg + 1;
var $totpgs = <?php echo $tpages; ?>; // Doesn't show echo !!!
console.log('Total Pages: ' + $totpgs);
if (newpg > $totpgs) {newpg = $totpgs} // limit page to total pages
curpg = newpg;
var $start = (newpg - 1) * 15 + 1;
console.log('Start: ' + $start);
$.ajax({
url:'pagination.php',
type:'POST',
data:{start:$start},
dataType:'text'
});
});