Jump to content

problem with a function to change order of items


spyke01

Recommended Posts

ok im trying to be able to move forums, or other items for that matter, with simple PHP functions. The order of items is of course stored in the orders field of a table, the lower the value, the closer to the top of the list it is. I am using this function to do it, but sometimes it freaks out, usualy in IE(wierd though it is), and wont do anything, usually when this happens, the order is set to 999 and stays there.

the code:
[code]
if ($_GET[action] == "moveforum") {
$sql = "SELECT forum_order FROM `forums` WHERE forum_id='$_GET[id]' LIMIT 1";
$result = mysql_query($sql);

if ($row = mysql_fetch_array($result)) { $current_order_num = $row[forum_order]; }
mysql_free_result($result);

if ($_GET[dir] == "up") { $target_order_num = ($current_order_num > 1) ? $current_order_num - 1 : 1; }
else { $target_order_num = $current_order_num + 1; }

$sql = "UPDATE `forums` SET forum_order='999' WHERE forum_id='$_GET[id]'";
$result = mysql_query($sql);

$sql = "UPDATE `forums` SET forum_order='$current_order_num' WHERE (forum_order='$target_order_num' AND forum_cat_id='$_GET[catid]')";
$result = mysql_query($sql);

$sql = "UPDATE `forums` SET forum_order='$target_order_num' WHERE forum_id='$_GET[id]'";
$result = mysql_query($sql);
}
[/code]
the style of link that activates it index.php?action=moveforum&id=$forum_id&catid=$forum_cat_id&dir=down

Does anyone see any problems with the code, or a simpler way of doing things?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.