1
我有這個腳本下面,我發現在SO上生成分頁和廣義上說,它的工作很好,但是因爲它從我的剪切和粘貼工作,我不明白如何實際生成鏈接這些變量在變量$ pagination中被回顯。PHP分頁鏈接生成
什麼它回聲是:
1< a href="index.php?page=2">2< a href="index.php?page=3">3< a hr_ef="?page=2"> Next
這些都不是工作(點擊)鏈接,我也希望能夠給他們的風格所以寧可輸出他們在HTML,而不是一個PHP的回聲,是這樣的:
<p><?php 1< a href="index.php?page=2">2< a href="index.php?page=3">3< a hr_ef="?page=2"> Next ?> </p>
下面是我使用的腳本:
<?php
/* Set current, prev and next page */
$page = (!isset($_GET['page']))? 1 : $_GET['page'];
$prev = ($page - 1);
$next = ($page + 1);
/* Max results per page */
$max_results = 10;
/* Calculate the offset */
$from = (($page * $max_results) - $max_results);
/* Query the db for total results.*/
$result = mysql_query("...");
$total_results = mysql_num_rows($result);
$total_pages = ceil($total_results/$max_results);
$pagination = '';
/* Create a PREV link if there is one */
if($page > 1)
{
$pagination .= '< a href="?page='.$prev.'">Previous</a> ';
}
/* Loop through the total pages */
for($i = 1; $i <= $total_pages; $i++)
{
if(($page) == $i)
{
$pagination .= $i;
}
else
{
$pagination .= '< a href="index.php?page='.$i.'">'.$i.'</a>';
}
}
/* Print NEXT link if there is one */
if($page < $total_pages)
{
$pagination .= '< a hr_ef="?page='.$next.'"> Next</a>';
}
/* Below is how you query the db for ONLY the results for the current page */
$query ="SELECT * FROM ... LIMIT $from, $max_results";
$result=mysql_query($query) or die(mysql_error());
$rsjobinfo=mysql_fetch_assoc($result);
do {?>
<div>
[Individual Row Output]
</div>
<?php } while ($rsjobinfo=mysql_fetch_assoc($result));
echo $pagination;
?>
有人能幫忙嗎?我想像它的一個小小的修復,但一如既往,將讚賞一個正確的方向踢。
感謝 丹
哈哈我知道這將是簡單的污垢。謝謝QD,我認爲a標籤的奇怪格式可能需要作爲腳本的一部分(我知道我知道,菜鳥)。造型應該沒有問題,現在我讓他們工作。再次感謝,巨大的進步:) – Dan
@丹好聽到,保持它;)祝你好運! – Quasdunk