如何在$ limit>之后创建新页面? 100?

时间:2014-02-13 12:25:40

标签: php mysql pagination

我希望在100行甚至50之后生成新页面。当我增加$limit时,所有行都会出现在单个页面上。请帮忙。

function new_uploaded_photos_bit2(){
$baseurl = _BASEURL_."/";
$limit ="100";  //Limit rows of 
$picnum='';
$userzoid='';
$id='';
global $relative_path;

$query="SELECT s1.fk_user_id,FROM_UNIXTIME(s1.created_on) FROM user_album2 s1
 LEFT JOIN user_album2 s2 ON s1.fk_user_id = s2.fk_user_id AND       FROM_UNIXTIME(s1.created_on) < FROM_UNIXTIME(s2.created_on)
WHERE s2.fk_user_id IS NULL ORDER by FROM_UNIXTIME(s1.created_on) DESC LIMIT $limit";

$result = mysql_query($query);
$i = 1;
$myreturn="<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" >";

while(($row = mysql_fetch_row($result)) !== false) {

$profileimage = get_photo($row[0],2);
$latestphotos = member_latest_photos($row[0],12);
$name = get_name($row[0]);
$profile=get_profile_link($row[0]);
$profiletype = get_profession2($row[0]);
$i++;

$myreturn.="<tr class=\"e".($i & 1)."\" valign=\"top\">";
$myreturn.="<td width=\"80\" align=\"left\" >
<a href=\"$baseurl$profile\">
<img src=\"${relative_path}memberpictures/thumbs/$profileimage\" height=\"0\"           height=\"0\" border=\"0\"></a>
</td>";
$myreturn.="<td valign=\"top\" align=\"left\" width=\"100%\">
<strong>$name </strong> / <font color=\"#444444\">$profiletype</font>
<br>
$latestphotos
</td> ";

$myreturn.="</tr>\n";
}
$myreturn.="</table>";
return $myreturn;
}

1 个答案:

答案 0 :(得分:0)

你应该研究'分页',因为这是你想要实现的目标。

MySQL的常见方法是将查询修改为限制结果数量,并使用偏移量

SELECT * 
FROM foo 
LIMIT [number of results to return] 
OFFSET [the record to start at] 

所以如果你想在'第1页'上获得50个结果

LIMIT 50 OFFSET 0 // 50 results starting at record 0

然后在'第2页'

LIMIT 50 OFFSET 50 // 50 results starting at record 50

您也可以使用速记表达式(可能更常见)

LIMIT [offset], [number of results]