HTML interesse |
|
Ik heb een functie geschreven die hier een beetje op lijkt.
Bij een groot aantal records zal hij wel veel queries uitvoeren dus dat moet je misschien ff aanpassen (ik ben er zelf ook nog mee bezig) maar misschien kan het je een beetje op weg helpen
<?
function ChangeOrder($id_update, $dir, $curplace, $cat_id)
{
// first we need to find and update all menuitems that are affected by updating the menustructure
if($dir=="up")
{
$cat_above = $curplace-1;
$query = "SELECT id FROM mc_prod_cat WHERE (mc_cat_id = $cat_id) AND (place=$cat_above)";
//echo $query;
$rs = mysql_query($query);
$nrs = mysql_num_rows($rs);
if($nrs!=0)
{
$id = mysql_result($rs, 0);
$query = "UPDATE mc_prod_cat SET place='$curplace' WHERE id=$id";
mysql_query($query);
$query = "UPDATE mc_prod_cat SET place='$cat_above' WHERE id=$id_update";
mysql_query($query);
}
}
if($dir=="down")
{
$cat_below = $curplace+1;
$query = "SELECT id FROM mc_prod_cat WHERE (mc_cat_id = $cat_id) AND (place=$cat_below)";
$rs = mysql_query($query);
$nrs = mysql_num_rows($rs);
if($nrs!=0)
{
$id = mysql_result($rs, 0);
$query = "UPDATE mc_prod_cat SET place='$curplace' WHERE id=$id";
mysql_query($query);
$query = "UPDATE mc_prod_cat SET place='$cat_below' WHERE id=$id_update";
mysql_query($query);
}
}
}
?>
<? function ChangeOrder($id_update, $dir, $curplace, $cat_id) { // first we need to find and update all menuitems that are affected by updating the menustructure if($dir=="up") { $cat_above = $curplace-1; $query = "SELECT id FROM mc_prod_cat WHERE (mc_cat_id = $cat_id) AND (place=$cat_above)"; //echo $query; if($nrs!=0) { $query = "UPDATE mc_prod_cat SET place='$curplace' WHERE id=$id"; $query = "UPDATE mc_prod_cat SET place='$cat_above' WHERE id=$id_update"; } } if($dir=="down") { $cat_below = $curplace+1; $query = "SELECT id FROM mc_prod_cat WHERE (mc_cat_id = $cat_id) AND (place=$cat_below)"; if($nrs!=0) { $query = "UPDATE mc_prod_cat SET place='$curplace' WHERE id=$id"; $query = "UPDATE mc_prod_cat SET place='$cat_below' WHERE id=$id_update"; } } } ?>
|