"SELECT * FROM art_article WHERE id<'$article_id' limit 0,3 order by id asc" 一个查询搞定
分两个查询完成取得当前和下一条 "SELECT * FROM art_article WHERE id>='$article_id' order by id limit 0,2" 取得上一条 "SELECT * FROM art_article WHERE id<'$article_id' order by id desc limit 0,1"
xuzuning(唠叨) 老大, 是不是可以这样:( 其中: $num,$_GET['num']为select count(*) from _table where id<'$article_id')if(!isset($_GET['num']) or ""==$_GET['num']){ mysql_query("select count(*) from _table where id<'$article_id'"); $num = ....; }else{ $num = $_GET['num']; } if(0==$num ){ mysql_query("SELECT * FROM art_article WHERE 1 order by id limit 0,2"); ....(就没有上一篇了) }else { mysql_query("SELECT * FROM art_article WHERE 1 order by id limit ".($num - 1).",3"); ...(当然,下一篇也是可能没有的) }
但next()和prev()函数如何实现?
只是要有一个跳转,得到上一篇或者下一篇的ID之后再跳转到正常页面。
先拉出一个结果集(),然后再使用next()或者prev()例:
<?php
$transport = array('foot', 'bike', 'car', 'plane');
$mode = current($transport); // $mode = 'foot';
$mode = next($transport); // $mode = 'bike';
$mode = next($transport); // $mode = 'car';
$mode = prev($transport); // $mode = 'bike';
$mode = end($transport); // $mode = 'plane';
?>
但用next()和prev()函数如何实现?
一个查询搞定
"SELECT * FROM art_article WHERE id>='$article_id' order by id limit 0,2"
取得上一条
"SELECT * FROM art_article WHERE id<'$article_id' order by id desc limit 0,1"
是不是可以这样:( 其中: $num,$_GET['num']为select count(*) from _table where id<'$article_id')if(!isset($_GET['num']) or ""==$_GET['num']){
mysql_query("select count(*) from _table where id<'$article_id'");
$num = ....;
}else{
$num = $_GET['num'];
}
if(0==$num ){
mysql_query("SELECT * FROM art_article WHERE 1 order by id limit 0,2");
....(就没有上一篇了)
}else {
mysql_query("SELECT * FROM art_article WHERE 1 order by id limit ".($num - 1).",3");
...(当然,下一篇也是可能没有的)
}