问题PHP分页 [英] Problem PHP pagination..
本文介绍了问题PHP分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有此代码
I have this code
<?php
$per_page = 8;
//get start variable
$start = $_GET['start'];
//count records
$record_count = mysql_num_rows(mysql_query("SELECT * FROM posts"));
//count max pages
$max_pages = $record_count / $per_page; //may come out as decimal
if (!$start)
$start = 0;
//display data
$get = mysql_query("SELECT * FROM posts LIMIT $start, $per_page");
while ($row = mysql_fetch_assoc($get))
{
// get data
$numelink = 'http://localhost/posts/list.php?'.$title.'';
$title = $row['title'];
$description = $row['description'];
$user = $row['user'];
$downloads = $row['downloads'];
$pict1 = $row['pict1'];
$pict2 = $row['pict2'];
$date = $row['date'];
$rezolution = $row['rezolution'];
$views = $row['views'];
$rank = $row['rank'];
$memberurl = 'http://localhost/user/'.$user.'';
echo '
<div id="posts_in"><div id="texture_pic"><img src="',$pict1,'" width="200" height="150" alt="pic1" /></div>
<div id="texture_content"><p align="left"> <a href="'.$numelink.'">'
,$title,
'</a></p><div id="posts_content_int">
<table width="192" height="76" border="1">
<tr>
<td height="16">Downloads:</td>
<td width="103">',$downloads,'</td>
</tr>
<tr>
<td height="16">Rank:</td>
<td width="103">',$rank,'</td>
</tr>
<tr>
<td width="16" height="16"> </td>
<td width="103"> </td>
</tr>
<tr>
<td height="16"> </td>
<td height="16"> </td>
</tr>
<tr>
<td height="16">Date-Add:</td>
<td height="16">',$date,'</td>
</tr>
<tr>
<td height="16">User:</td>
<td height="16"><a href="', $memberurl, '">',$user,'</a></td>
</tr>
</table>
</div><div id="texture_content_int"><table width="192" height="111" border="1">
<tr>
<td width="69" height="16">Complete:</td>
<td width="107">',$downloads,'</td>
</tr>
<tr>
<td height="16">Rezolution:</td>
<td width="107">',$rezolution,'</td>
</tr>
<tr>
<td>Views</td>
<td>',$views,'</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</div>
</div>
</div>
';
}
//setup prev and next variables
$prev = $start - $per_page;
$next = $start + $per_page;
//show prev button
if (!($start<=0))
echo "<a href='../posts/index.php?start=$prev'>Prev</a> ";
//show page numbers
//set variable for first page
$i=1;
for ($x=0;$x<$record_count;$x=$x+$per_page)
{
if ($start!=$x)
echo "<a href='../posts/index.php?start=$x'>$i</a> ";
else
echo " <a href='../posts/index.php?start=$x'>$i</a> ";
$i++;
}
//show next button
if (!($start>=$record_count-$per_page))
echo "<a href='../posts/index.php?start=$next'>Next</a>";
?>
这是我的代码..我需要更好的代码,因为这在$ numelink上有问题.有人知道我可以做些什么来解决它?更好的分页吗?
This is my code ..i need a better code because this is buggy on $numelink. Somebody know what i can do to fix it ? Oe a better pagination ?
推荐答案
per_page = 8 ; // 获取开始变量
per_page = 8; //get start variable
start =
start =
_GET [ ' 开始']; // 计数记录
_GET['start']; //count records
这篇关于问题PHP分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文