for example,
Code: Select all
<?php
$sql = "SELECT * FROM `links` ORDER BY `position`";
$result = $db->sql($sql);
if (mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_assoc($result))
{
if ($_SESSION['loggedin'] == 1 && isset($_GET['admin']))
{
$template->svar(array('LINKS_ADMIN' => '<a href="?goto=links&admin=1&move=up&position='.$row['position'].'">Move Up</a> <a href="?goto=links&admin=1&move=down&position='.$row['position'].'">Move Down</a>'));
}
$template->loadfile('links');
}
}
?>Code: Select all
<?php
if ($_SESSION['loggedin'] == 1 && !empty($_GET['admin']) && !empty($_GET['move']) && !empty($_GET['position']))
{
switch ($_GET['move'])
{
case 'up' :
$sql = "UPDATE `links` SET `position` = (`position` + 1) WHERE `position` = '".$_GET['position']."', SET `position` = (`position` - 1) WHERE `position` = '".($_GET['position'] + 1)."'";
break;
case 'down' :
$sql = "UPDATE `links` SET `position` = (`position` - 1) WHERE `position` = '".$_GET['position']."', SET `position` = (`position` + 1) WHERE `position` = '".($_GET['position'] - 1)."'";
break;
}
$db->sql($sql);
}
?>My question is, how can I succesfuly accomplish this move position business if one of the rows is deleted by an admin. It will attempt to update a row that does not exist, because the position has been deleted.
my table looks like this
Code: Select all
ID (auto-incremented)
POSITION
TITLE
etc.