日期:2014-05-17 浏览次数:20660 次
<!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" />
<title>实现新闻的上移下移功能</title>
</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=new mysql("localhost","root","root","test"," ","gbk");
if(!emptyempty($_GET["weight"])){
if($_GET["move"]=="up"){
//获取上一条新闻信息
$query=$conn->query("select * from `article` where `weight` > '$_GET[weight]' order by `weight` asc limit 1");
if($conn->db_num_rows(query)>0){
$rows=$conn->fetch_array($query);
$conn->query("update `article` set `weight`='$rows[weight]' where `weight`='$_GET[weight]'");
$conn->query("update `article` set `weight`='$_GET[weight]' where `ID`='$rows[ID]'");
}else{
echo "<script>alert('已经在最顶上');</script>";
}
}else if($_GET["move"]=="down"){
//获取下一条新闻信息
$query=$conn->query("select * from `article` where `weight` < '$_GET[weight]' order by `weight` desc limit 1");
if($conn->db_num_rows(query)>0){
$rows=$conn->fetch_array($query);
$conn->query("update `article` set `weight`='$rows[weight]' where `weight`='$_GET[weight]'");
$conn->query("update `article` 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>