日期:2014-05-16 浏览次数:21055 次
$colname_rs = "-1"; if (isset($_GET['id'])) { $colname_rs = $_GET['id']; } mysql_select_db($database_conn, $conn); $query_rs = sprintf("SELECT * FROM news WHERE id = %s", GetSQLValueString($colname_rs, "int")); $rs = mysql_query($query_rs, $conn) or die(mysql_error()); $row_rs = mysql_fetch_assoc($rs); $totalRows_rs = mysql_num_rows($rs); $next_sql="SELECT * FROM news WHERE id >$colname_rs ORDER BY id ASC LIMIT 1 "; $rsnext= mysql_query($next_sql, $conn) or die(mysql_error()); $row_next = mysql_fetch_assoc($rsnext); $prev_sql="SELECT * FROM news WHERE id <$colname_rs ORDER BY id DESC LIMIT 1 "; $rsprev= mysql_query($prev_sql, $conn) or die(mysql_error()); $row_prev = mysql_fetch_assoc($rsprev); $max_sql="SELECT MAX(id) FROM news"; $rsmax = mysql_query($max_sql, $conn) or die(mysql_error()); $row_max = mysql_fetch_array($rsmax); $min_sql="SELECT MIN(id) FROM news"; $rsmin = mysql_query($min_sql, $conn) or die(mysql_error()); $row_min = mysql_fetch_array($rsmin); $min_id=mysql_result($rsmin,0); $max_id=mysql_result($rsmax,0); switch ($colname_rs) { case $min_id : $ptext="没有了"; $ntext= "<a href=\"index.php?id=".$row_next['id']."\">".$row_next['tiltle']."</a>"; break; case $max_id: $ptext= "<a href=\"index.php?id=".$row_prev['id']."\">".$row_prev['tiltle']."</a>"; $ntext="没有了"; break; default: $ptext= "<a href=\"index.php?id=".$row_prev['id']."\">".$row_prev['tiltle']."</a>"; $ntext= "<a href=\"index.php?id=".$row_next['id']."\">".$row_next['tiltle']."</a>"; }
<?php echo $ptext; ?>
<?php echo $ntext; ?>