php 实现上移和下移

1、order.php

 

<!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=gb2312" /> 
<name>实现新闻的上移下移功能</name> 
</head> 
  
<body> 
<style> 
*{font-size:12px;} 
td{height:24px; line-height:24px; text-align:center} 
</style> 
  
<?php 
header("Content-type:text/html;charset=gb2312"); 
//include("mysql.class.php"); 
$conn=mysql_connect("localhost","root","12345678") or die("连接失败");
$db=mysql_select_db("fqwh");
if(!empty($_GET["weight"])){ 
    if($_GET["move"]=="up"){ 
        //获取上一条新闻信息 
        $query=mysql_query("select * from `usr` where `weight` > '$_GET[weight]' order by `weight` asc limit 1"); 
        if(mysql_num_rows($query)>0){ 
            $rows=mysql_fetch_array($query); 
            mysql_query("update `usr` set `weight`='$rows[weight]' where `weight`='$_GET[weight]'"); 
            mysql_query("update `usr` set `weight`='$_GET[weight]' where `id`='$rows[id]'"); 
        }else{ 
            echo "<script>alert('已经在最顶上');</script>"; 
        } 
    }else if($_GET["move"]=="down"){ 
        //获取下一条新闻信息 
        $query=mysql_query("select * from `usr` where `weight` < '$_GET[weight]' order by `weight` desc limit 1"); 
        if(mysql_num_rows($query)>0){ 
            $rows=mysql_fetch_array($query); 
            mysql_query("update `usr` set `weight`='$rows[weight]' where `weight`='$_GET[weight]'"); 
            mysql_query("update `usr` set `weight`='$_GET[weight]' where `id`='$rows[id]'"); 
        }else{ 
            echo "<script>alert('已经在最底下');</script>"; 
        } 
    } 

?> 
<table border="1" cellpadding="0" cellspacing="0" width="300" align="center"> 
        <caption>文章上下移动</caption> 
        <tr> 
            <td>id</td><td>标题</td><td>移动</td> 
        </tr> 
<?php 
$query=mysql_query("select * from `usr` order by `weight` desc"); 
if(mysql_num_rows($query)>0){ 
while($rows=mysql_fetch_array($query)){ 
    $aid[].=$rows["id"]; 
?> 
        <tr> 
            <td><?php echo $rows["id"]?></td> 
            <td><?php echo $rows["name"]?></td> 
            <td><a href="<?php $PHP_SELF?>?weight=<?php echo $rows[weight]?>&move=up">上移</a>/<a href="<?php $PHP_SELF?>?weight=<?php echo $rows[weight]?>&move=down">下移</a></td> 
        </tr> 
  
<?php 
    } 

?> 
    </table> 
</body> 
</html> 

 

2、sql脚本 fqwh.sql

/*
MySQL Data Transfer
Source Host: localhost
Source Database: fqwh
Target Host: localhost
Target Database: fqwh
Date: 2012-8-24 16:37:33
*/

SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for raty
-- ----------------------------
CREATE TABLE `raty` (
  `id` varchar(255) NOT NULL,
  `voter` varchar(255) DEFAULT NULL,
  `total` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Table structure for usr
-- ----------------------------
CREATE TABLE `usr` (
  `id` varchar(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL,
  `chinesename` varchar(255) NOT NULL,
  `email` varchar(255) DEFAULT NULL,
  `qq` varchar(255) DEFAULT NULL,
  `department` varchar(255) DEFAULT NULL,
  `housename` varchar(255) DEFAULT NULL,
  `groupid` int(11) DEFAULT NULL,
  `weight` varchar(11) NOT NULL,
  PRIMARY KEY (`id`,`weight`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records
-- ----------------------------
INSERT INTO `usr` VALUES ('1', '1', '1', '1', '1', '1', '1', '1', '1', '2');
INSERT INTO `usr` VALUES ('2', '2', '2', '2', '2', '2', '2', '2', '2', '1');
INSERT INTO `usr` VALUES ('3', '3', '3', '3', '3', '3', '3', '3', '3', '3');
INSERT INTO `usr` VALUES ('4', '123123', '1111', '4', null, null, null, null, null, '4');
INSERT INTO `usr` VALUES ('5', 'qwe', '111111', '5', null, null, null, null, null, '5');
INSERT INTO `usr` VALUES ('6', 'sdf', '123456', '6', null, null, null, null, null, '6');


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值