µ±Ç°Î»ÖãºLinux½Ì³Ì - Php - ʵÏÖÇ¿´óµÄ·­Ò³Ìøת¹¦ÄÜ(Ò»)

ʵÏÖÇ¿´óµÄ·­Ò³Ìøת¹¦ÄÜ(Ò»)

ÎÒÃǶ¼ÖªµÀÓà php+mysql ÔÚ web ҳʵÏÖÊý¾Ý¿â×ÊÁÏÈ«²¿ÏÔʾÊǷdz£¼òµ¥¶øÓÐȤµÄ,Êý¾Ý¿â×ÊÁϺÜÉÙµÄÇé¿öÏÂÒ³ÃæÏÔʾ»¹ÊÇÈÃÈËÂúÒâµÄ,µ«Êǵ±Êý¾Ý¿â×ÊÁϷdz£¶àµÄÇé¿öÏÂ,Ò³ÃæµÄÏÔʾÇé¿ö½«»á±äµÄ·Ç³£Ôã¸â,ÏÂÃæ¾ÍÀ´½éÉÜÒ»ÏÂÈçºÎʵÏÖµ±Ç°Ò³ÃæÊý¾Ý×ÊÁÏÏÔʾÊýÁ¿¼°ÈçºÎʵÏÖ¶¯Ì¬µÄ·­×ª¹¦ÄÜ.

ÕâÀォ½éÉÜÁ½ÖÖ·­Ò³ÏÔʾ¹¦ÄܵÄʵÏÖ:
-----------------------------------------------------------
ÏȽéÉÜÒ»ÏÂÔÚ·­Ò³ÖÐÓõ½µÄÊý¾Ý¿âÓï·¨:

mysql_query("select * from table order by id desc");

ÕâÌõÊý¾Ý¿âÓï¾äÔÙÊìϤ²»¹ýÁË,ÊÇÓÃÀ´ËÑË÷¼Ç¼²¢µ¹ÐòµØÏÔʾ³öÀ´,µ«²¢²»ÄÜÔÚ·­Ò³¹¦ÄÜÖÐÆð×÷ÓÃ,¶øÏÂÃæÕâ¸öÀ©Õ¹Á˵ÄÓï·¨²ÅÊÇʵÏÖ·­Ò³µÄºËÐŦÄÜ:

mysql_query("select * from table order by id desc limit $start,$limit");

ÕâÀïµÄ $start ÊÇÊý¾Ý¿âËÑË÷µÄÆðʼÐÐ,$limit ÊÇ´ÓÆðʼÐпªÊ¼ËÑË÷µ½ $limit Ìõ¼Ç¼½áÊø,ºÃÁË,ÓÐÁËÕâ¸öºËÐŦÄܺó,ÎÒÃÇ¿ÉÒÔ¿ªÊ¼·­Ò³¹¦ÄÜÁË;
-----------------------------------------------------------
µÚÒ»ÖÖ·­Ò³¹¦ÄÜ:
ÕâÀï½éÉܵŦÄÜÊÇ·­Ò³¹¦ÄÜÖÐ×î¼òµ¥µÄÒ»ÖÖ,Ö»ÄÜʵÏÖÏòÇ°·­Ò³ºÍÏòºó·­Ò³,±¾Õ¾µÄ·Ç³£ÐÂÎźÍÏÂÔØÖÐÐĵķ­Ò³¹¦ÄܾÍÊÇÕâÖÖ.

ÏȽéÉÜ·­Ò³¹¦ÄÜʵÏÖµÄ˼·:
ÏÈÈ·¶¨µ±Ç°Ò³¹Ì¶¨ÏÔʾµÄÊý¾Ý¼Ç¼ÊýÁ¿,¼ÙÉèΪ 20 Ìõ¼Ç¼,É趨 $limit µÄֵΪ 20: $limit=20;

ÏÔʾÊý¾Ý¿â¼Ç¼ʱ,±ØÐëÊÇ´ÓµÚÒ»Ìõ¿ªÊ¼ÏÔʾ,ËùÒÔÕâÀïÉèÖà $start µÄ³õʼֵΪ 0:$start=0;

¶ø·­Ò³¹¦ÄܵÄʵÏÖÒÀÀµ $start µÄ¶¯Ì¬±ä»¯,µ±Ïòºó·­Ò³Ê± $start ¹æÂɵؼÓÉÏ $limit:$start+$limit;¶øÏòÇ°·­Ò³Ê± $start Ôò¹æÂɵؼõÈ¥ $limit:$start-$limit;

ÓÐÁËÒÔÉϵÄ˼·ºó,¿ÉÒÔ¿ªÊ¼Éè¼Æ³ÌÐòÁË page.php:

<?
//ÉèÖõ±Ç°Ò³ÏÔʾµÄÊýÁ¿(Õâ¸öÊýÁ¿¿ÉÈÎÒâÉèÖÃ)
$limit=20;

//³õʼ»¯Êý¾Ý¿âËÑË÷Æðʼ¼Ç¼
if (!empty($start)) $start=0;

mysql_connect("localhost","","");
mysql_select_db(database);

//ÉèÖÃÊý¾Ý¿â¼Ç¼×ÜÊý
$result=mysql_query("select * from table");
$num_max=mysql_numrows($result);

$result=mysql_query("select * from table order by id desc limit $start,$limit);
$num=mysql_numrows($result);

echo "<table><tr><td>·­Ò³¹¦ÄÜ</td></tr>";

if (!empty($num)) {
for ($i=0;$i<$num;$i++) {
$val=mysql_result($result,$i,"val");
$val1=mysql_result($result,$i,"val1");
echo "<tr><td>$val</td><td>$val1</td></tr>";
}
}

echo "<tr><td>";

//ÉèÖÃÏòÇ°·­Ò³µÄÌøת
$prve=$start-$limit;
if ($prve>=0) {
echo "<a href=page.php?start=$prve>prve</a>";
}

//ÉèÖÃÏòºó·­Ò³µÄÌøת
$next=$start+$limit;
if ($next<$num_max) {
echo "<a href=page.php?start=$next>next</a>";
}

echo "</td></tr></table>";
?>

Ò»¸öÇ°·­,ºó·­¹¦ÄܵijÌÐòÍê³ÉÁË.µ«Õâ¸ö¹¦ÄܶԴ¦Àí¸ü¶à×ÊÁÏÏÔʾʱ,½«»áÏԵúÜÀÛ׸.ÏÂÃ潫»á¼ÌÐø½éÉܹ¦ÄܸüÇ¿´ó,¸ü¼Ó¸´Ôӵķ­Ò³¹¦ÄÜ--Ñ­»··­Ò³(ÎÒÒ»Ö±¶¼Õâô½Ð,ÒòΪÕÒ²»µ½¸üºÏÊʵĽз¨).:)