2013-10-15 160 views
0

好的,首先我會告訴你應該如何工作:我有一個圖像鏈接的頁面,點擊圖像,該鏈接的信息出現在另一個div中。我使用jquery/ajax將鏈接標識發佈到一個php文件並將該數據返回給所選的div。 鏈接應分頁,以便一次顯示4個。頁面加載時的Ajax分頁?

這就是發生了什麼:後部分是好的,當我點擊鏈接正確的數據顯示在選定的div。我不知道如何使鏈接div分頁。我需要他們頁面加載時分頁,現在當頁面加載所有鏈接顯示,然後當我點擊一個鏈接正確的金額(4)顯示!

這是我的HTML與2周的div:

<div class="dogsrehomeandrehomed"> 
<?php 
include 'inc/connect.php'; 
$q = mysqli_query($link, "SELECT filename, id, name, age, sex FROM gallery WHERE 
gallery = 1 ORDER BY id DESC") or die (mysql_error()); 
while($row = mysqli_fetch_array($q)){ 
$data = $row['filename']; 
$file = substr($data, strpos($data, "/") + 1); 
echo"<div class='homedogs'>", 
"<a href={$row['id']} class='dogchoice'>", 
"<img class='nailthumb-container3' src='$file' alt='{$row['name']}. Image' />", 
"</a>", 
"<br />", 
'NAME: ',$row['name'],"<br />",'AGE: ',$row['age'],"<br />",'SEX: ',$row['sex'], 
"</div>"; 
} 
?> 
</div> 

<div class="dog"> 
<?php 
include 'inc/connect.php'; 
$q = mysqli_query($link, "SELECT * FROM gallery WHERE gallery = 1 ORDER BY id DESC 
LIMIT 1") or die (mysql_error()); 
while($row = mysqli_fetch_array($q)){ 
$data = $row['filename']; 
$file = substr($data, strpos($data, "/") + 1); 
echo"<div class='rehomediv'>", 
"<img class='nailthumb-container2' src='$file' alt='{$row['name']}. Image' />","<br 
/>", 
"<div class='nameagesex'>", 
'NAME: ',$row['name'],"<br />",'AGE: ',$row['age'],"<br />",'SEX: ',$row['sex'], 
"</div>", 
"<div class='description'>", 
nl2br($row['description']), 
"</div>", 
"</div>"; 
} 
?>   
</div> 
<script src="js/dog.js"></script> 

這是我dog.js文件:

$('a.dogchoice').click(function(e) { 
e.preventDefault(); 
var linkClass = $(this).attr("class"); 
var linkText = new String(this); 
var categoryValue = linkText.substring(linkText.lastIndexOf('/') + 1); 
var params = {}; 
params[linkClass] = categoryValue; 
$.post('inc/dogchoice.php', params, function(data) { 
    var totalRecords = $(data).length; 
    var pageSize = 4; 
    var numOfPages = Math.ceil(totalRecords/pageSize); 
    var i, 
     pageLinks = '<div class="pageLinks">'; 
    for (i = 0; i < numOfPages; i++) { 
     pageLinks += '<a href="#" onclick="showDogLinks(' + i + ');return false;">' + (i 
     + 1) + '<\/a> '; 
    } 
    pageLinks += '<\/div>'; 
    $('.dog').html(pageLinks + data); 
    showDogLinks(0); 
}); 

}); 

//function to slice up records into pages 
function showDogLinks(pageNo) { 
var perPage = 4; 
var start = pageNo * perPage; 
var end = start + perPage; 
$('.homedogs').hide().filter(function(index) { 
    return ((index > (start-1)) && (index < end)); 
}).show(); 
} 

誰能幫助? 感謝您的期待

回答

0

我整理了它。我只用PHP分頁鏈接容器。

感謝您的期待..