您的位置: 首页 - PHP代码 - php中实现上一篇下一篇

php中实现上一篇下一篇

编辑:admin     时间:2010-12-3    9:56:03  来自:北京蓝网网络技术有限公司


<?php
//连接数据库
$conn=mysql_connect('localhost','root');
mysql_select_db('img',$conn);
mysql_query('set names utf8');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>产品展示</title>
<style>
#main{width:800px; margin: 0 auto; padding:0px; border:dashed 1px #ccc; height:200px;}
#main dt{ width:400px; margin: 0px; padding:5px 0; height:auto; float:left; text-align:center;}
</style>
</head>
<?php

 $id=$_GET['id'];
 if(isset($_GET['action'])){
   $action=$_GET['action'];
   $fid=$_GET['fid'];
 }
    switch ($action){
     case "down":
      $result=mysql_query("select * from path_img where id > $fid limit 1");
      break;
     case "up":
      $result=mysql_query("select * from path_img where id<  $fid  order by id desc limit 1");
      break;
     default:
            $result=mysql_query("select * from path_img where id=$id limit 1");
    }
 
 if(mysql_num_rows($result)<1){
  echo "<script>alert('产品不存在');history.back();</script>";
 }

?>
<body>
 <div id="main">
<?php
 while(!!$row=mysql_fetch_array($result)){
  $html['id']=$row['id'];
  $html['title']=$row['title'];
  $html['path']=$row['path'];
 }
?>
 <dt><?php echo $html['title']?></dt>
  <dt><img src="<?php echo $html['path']?>"></img></dt>
 <dt><a href="?fid=<?php echo $html['id']?>&action=up">上一条</a></dt>
  <dt><a href="?fid=<?php echo $html['id']?>&action=down">下一条</a></dt>
 </div>
</body>
</html>
 

分类:PHP代码 | 评论:0 | 引用:0 | 浏览:248  | 引用本文