Hi,
Hope this will get you started. I use it to change the order of menu-items in websites management module I am writing. Not finished, but working, I suppose. The variable below is the ID of the page below which the page ($pageid) has to be placed. I use variables for my tablenames, so I can use these codes across systems / sites, replace for your own tables. function getvar is a personal function I use to get variables from usersubmitted data, including basic verification. just replace with your own functions fo rthis.
if(isset($_POST[form])) // form was submitted
{
$below = getvar('editable', -1, 1);
$pageid = getvar('modifypage', -1, 1);
if($below == -1) // place at top of menu
{
$query = "select * from $menu_table where M_page_nr = $menu_parent order by 'sortorder' desc limit 1";
echo $query;
$result = mysql_query($query) or die('Something went wrong when resorting in resort.q1: '.mysql_error());
while($row = mysql_fetch_array($result))
{
$sort_location_nw = $row['M_sortorder'];
}
$move_rest_query = "update $menu_table
set M_sortorder = M_sortorder+1
where (M_sortorder >= $sort_location_nw)
and (M_p_nr = $menu_parent)";
}
else
{
$sort_location_nw = $below;
if($sort_location_nw >= $sortorder) // If the new location is below the old location, shift up
{
$move_rest_query = "update $menu_table
set M_sortorder = M_ortorder-1
where (M_sortorder > $sortorder)
and (M_sortorder <= $sort_location_nw)
and (M_p_nr = $menu_parent) ";
}
else // If the new location is below the new location, shift down
{
$move_rest_query = "update $menu_table
setM_sortorder = M_sortorder+1
where (M_sortorder) > ($sort_location_nw)
and (M_sortorder < $sortorder)
and (M_p_nr = $menu_parent)";
}
}
echo $move_rest_query;
$move_rest = mysql_query($move_rest_query) or die('Could not resort the table in resort.q2'.mysql_error());
$movepage = "update $menu_table
set M_sortorder = $sort_location_nw
where M_page_nr = $pageid";
echo $movepage;
$moved_page = mysql_query($movepage);
}