php文章排序后进行前移后移,写了语句没起作用,不知道哪出问题了? php排序前移后移 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 会不会是文章的sort并不是连续的,就前移来说你取sort-1作为调教来修改有可能没修改到数据库记录,然后即使当前sort+1可能还是没有比下个文章的sort大 /*前移*/if($result=='up'){ $sql0=$db->query("select sort from ".$db->table('product')." where id='$id'"); $row=$db->fetch_array($sql0); if(!$row){ $oldpx=1; }else{ $oldpx=$row['sort']; } if($oldpx>1){ $db->query("update ".$db->table('product')." set sort=sort+1 where sort=".$oldpx-1); $db->query("update ".$db->table('product')." set sort=sort-1 where id=".$id); } header("Location:product_list.php\n"); exit;}/*后移*/if($result=='down'){ $sql1=$db->query("select sort from ".$db->table('product')." where id='$id'"); $row=$db->fetch_array($sql1); if(!$row){ $oldpx=9999; }else{ $oldpx=$row['sort']; } $sql2=$db->query("select sort from ".$db->table('product')." order by sort desc limit 1"); $rows=$db->fetch_array($sql2); if(!$rows){ $maxpx=9999; }else{ $maxpx=$rows['sort']; } if($oldpx<$maxpx){ $db->query("update ".$db->table('product')." set sort=sort-1 where sort=".$oldpx+1); $db->query("update ".$db->table('product')." set sort=sort+1 where id=".$id); } header("Location:product_list.php\n"); exit;}红色标注的那里改成 where id='".$id."'"); if($_REQUEST["action"] == "up"){ uppx($_REQUEST['goods_id']);}elseif($_REQUEST["action"] == "down"){ downpx($_REQUEST['goods_id']);}function uppx($goods_id){ if(!$goods_id) { $goods_id=0; } $sql=$GLOBALS['db']->query("select px from ".$GLOBALS['db']->table('product')." where id=".$goods_id); $rs=$GLOBALS['db']->fetch_array($sql); if(!$rs) { $oldpx = 1; } else { $oldpx = $rs['px']; } if($oldpx>1){ $oldpx=$oldpx-1; $GLOBALS['db']->query("update ".$GLOBALS['db']->table('product')." set px=px+1 where px=".$oldpx); $GLOBALS['db']->query("update ".$GLOBALS['db']->table('product')." set px=px-1 where id=".$goods_id); } header("Location:product_list.php"); exit; }function downpx($goods_id){ if(!$goods_id) { $goods_id=0; } $sql=$GLOBALS['db']->query("select px from ".$GLOBALS['db']->table('product')." where id=".$goods_id); $rs=$GLOBALS['db']->fetch_array($sql); if(!$rs) { $oldpx=1; } else { $oldpx=$rs['px']; } //假如$oldpx=1的话 $sql1=$GLOBALS['db']->query("select * from ".$GLOBALS['db']->table('product')." order by px desc limit 1"); $row=$GLOBALS['db']->fetch_array($sql1); if(!$row) { $maxpx=999; } else { $maxpx=$row['px']; } //到这里那么最大的$maxpx=4 if($oldpx<$maxpx){ $oldpx=$oldpx+1; $GLOBALS['db']->query("update ".$GLOBALS['db']->table('product')." set px=px-1 where px=".$oldpx); $GLOBALS['db']->query("update ".$GLOBALS['db']->table('product')." set px=px+1 where id=".$goods_id); } header("Location:product_list.php"); exit; }根据你那代码我自己完整的演示了一遍,实现你要的效果了 怎样用js刷新验证码页面(php做的) 请教请教 一Q币的问题! 根据timestamp类型数据的早晚读取数据库内的数据 file_get_contents获取远程文件时没有反应 php 查询 PHPstorm调不出xdebug PHP的officeCOM对象编程 我做的下載文件的程序怎麼把文件下載后文件格式變了,打不開,請大家幫忙!!! 哪位兄弟有完善的新闻管理、专题文章管理的源码? jquery批量上传是Post提交导致整个表单没法提交至后台? thinkphp3.1视图模型生成的SQL语句执行不了
/*前移*/
if($result=='up'){
$sql0=$db->query("select sort from ".$db->table('product')." where id='$id'");
$row=$db->fetch_array($sql0);
if(!$row){
$oldpx=1;
}else{
$oldpx=$row['sort'];
}
if($oldpx>1){
$db->query("update ".$db->table('product')." set sort=sort+1 where sort=".$oldpx-1);
$db->query("update ".$db->table('product')." set sort=sort-1 where id=".$id);
}
header("Location:product_list.php\n");
exit;
}
/*后移*/
if($result=='down')
{
$sql1=$db->query("select sort from ".$db->table('product')." where id='$id'");
$row=$db->fetch_array($sql1);
if(!$row){
$oldpx=9999;
}else{
$oldpx=$row['sort'];
}
$sql2=$db->query("select sort from ".$db->table('product')." order by sort desc limit 1");
$rows=$db->fetch_array($sql2);
if(!$rows){
$maxpx=9999;
}else{
$maxpx=$rows['sort'];
}
if($oldpx<$maxpx){
$db->query("update ".$db->table('product')." set sort=sort-1 where sort=".$oldpx+1);
$db->query("update ".$db->table('product')." set sort=sort+1 where id=".$id);
}
header("Location:product_list.php\n");
exit;
}红色标注的那里改成 where id='".$id."'");
if($_REQUEST["action"] == "up"){
uppx($_REQUEST['goods_id']);
}
elseif($_REQUEST["action"] == "down"){
downpx($_REQUEST['goods_id']);
}function uppx($goods_id)
{
if(!$goods_id)
{
$goods_id=0;
}
$sql=$GLOBALS['db']->query("select px from ".$GLOBALS['db']->table('product')." where id=".$goods_id);
$rs=$GLOBALS['db']->fetch_array($sql);
if(!$rs)
{
$oldpx = 1;
}
else
{
$oldpx = $rs['px'];
}
if($oldpx>1){
$oldpx=$oldpx-1;
$GLOBALS['db']->query("update ".$GLOBALS['db']->table('product')." set px=px+1 where px=".$oldpx);
$GLOBALS['db']->query("update ".$GLOBALS['db']->table('product')." set px=px-1 where id=".$goods_id);
}
header("Location:product_list.php");
exit;
}function downpx($goods_id)
{
if(!$goods_id)
{
$goods_id=0;
}
$sql=$GLOBALS['db']->query("select px from ".$GLOBALS['db']->table('product')." where id=".$goods_id);
$rs=$GLOBALS['db']->fetch_array($sql);
if(!$rs)
{
$oldpx=1;
}
else
{
$oldpx=$rs['px'];
}
//假如$oldpx=1的话
$sql1=$GLOBALS['db']->query("select * from ".$GLOBALS['db']->table('product')." order by px desc limit 1");
$row=$GLOBALS['db']->fetch_array($sql1);
if(!$row)
{
$maxpx=999;
}
else
{
$maxpx=$row['px'];
}
//到这里那么最大的$maxpx=4
if($oldpx<$maxpx){
$oldpx=$oldpx+1;
$GLOBALS['db']->query("update ".$GLOBALS['db']->table('product')." set px=px-1 where px=".$oldpx);
$GLOBALS['db']->query("update ".$GLOBALS['db']->table('product')." set px=px+1 where id=".$goods_id);
}
header("Location:product_list.php");
exit;
}根据你那代码我自己完整的演示了一遍,实现你要的效果了