我正在尝试用 PHP 做一个简单的 CMS。在滑块管理中,我想更改添加照片的顺序。
<a href="slideup.php?order=<?php echo $result['order']; ?>&id=<?php echo $result['id']; ?>" title="Up"><img src="../images/up.png" alt="Up" /></a>
<a href="slidedown.php?order=<?php echo $result['order']; ?>&id=<?php echo $result['id']; ?>" title="Down"><img src="../images/down.png" alt="Down" /></a>
它正在发送相关的 php 页面、当前顺序和幻灯片 ID。
幻灯片.php
<?php
include('includes/functions.php');
$order=$_REQUEST['order'];
$id=$_REQUEST['id'];
goUp($order, $id);
?>
滑下.php
<?php
include('includes/functions.php');
$order=$_REQUEST['order'];
$id=$_REQUEST['id'];
goDown($order, $id);
?>
函数.php
function goUp($order, $id)
{
$db = new DB_CONNECT();
if(!$order == 1)
{
$neworder = $order - 1;
mysql_query("UPDATE `slider` SET `order`='$order' WHERE `order`='$neworder'") or die(mysql_error());
mysql_query("UPDATE `slider` SET `order`='$neworder' WHERE `id`='$id'") or die(mysql_error());
}
header('Location: ../admin/slider.php');
}
function goDown($order, $id)
{
$db = new DB_CONNECT();
$totalslide = 0;
$query = mysql_query("SELECT COUNT(`id`) as count FROM `slider`") or die(mysql_error());
$result = mysql_fetch_array($query);
$totalslide = $result['count'];
if(!$order == $totalslide)
{
$neworder = $order + 1;
mysql_query("UPDATE `slider` SET `order`='$order' WHERE `order`='$neworder'") or die(mysql_error());
mysql_query("UPDATE `slider` SET `order`='$neworder' WHERE `id`='$id'") or die(mysql_error());
}
header('Location: ../admin/slider.php');
}
当我单击图标时,代码可以正常工作。但结果,什么也没有发生。我的代码有问题还是逻辑错误?
谢谢你。