Hi,
I have this code that adjusts the position of the subjects and the pages in my site.
This is working where the value of the radio button = 1 (which is = showing, in the database - And 0 = Not showing) And I am talking about pages for my site :-)
Im pulling the values from the form here:
$visible = ($_POST['visible']);
$position = ($_POST['position']);
$oldposition = ($_POST['oldposition']);
$pid = ($_POST['pid']);
$subjectid = ($_POST['subjectid']);
$oldsubjectid = ($_POST['oldsubjectid']);
$pagetitle = ($_POST['pagetitle']);
$description = ($_POST['description']);
$keywords = ($_POST['keywords']);
$linklabel = ($_POST['linklabel']);
$pagebody = ($_POST['pagebody']);
This code below works perfect for adjusting the positions of both pages or subjects when the value of the radio button is = 1..
(I know maybe its long, Im new to it)
Which is = $visible from the above written:
if($visible = '1'){ // The value of the radio button, which means the page will display
/* Hvis en PAGE flytter subject ($oldsubjectid != subjectid), så bliver eksisterende sider i det "nye" subject 1 højere, og siderne i det "gamle" subject bliver en mindre*/
if($oldsubjectid != $subjectid){
$queryAdjustDownForOldSubject = mysqli_query($myConnection, "UPDATE pages SET pos = pos - 1 WHERE pos > $oldposition AND subjectid = $oldsubjectid");
$queryAdjustUpForNewSubject = mysqli_query($myConnection, "UPDATE pages SET pos = pos + 1 WHERE pos >= $position AND subjectid = $subjectid");
$query = mysqli_query($myConnection, "UPDATE pages SET subjectid='$subjectid', pagetitle='$pagetitle', linklabel='$linklabel', description='$description', keywords='$keywords', pos='$position', pagebody='$pagebody', showing='$visible', lastmodified='now()' WHERE id='$pid'") or die (mysqli_error($myConnection));
echo '<div align="center">Operation Completed Successfully! Head back to the admin home page, or the main website to see your changes!<br /><br /><a href="login/admin.php">Click Here For Admin home!</a>
<br /><br /><a href="../" >Or head back to view the live website!</a></div>';
exit();
}
// Hvis en PAGE IKKE skifter subject, men får en LAVERE position, f.eks NED til position 2 FRA position 12
if ($oldposition > $position){
$queryDown = mysqli_query($myConnection, "UPDATE pages SET pos = pos + 1 WHERE pos >= $position AND pos <= $oldposition AND subjectid = $subjectid");
$query = mysqli_query($myConnection, "UPDATE pages SET subjectid='$subjectid', pagetitle='$pagetitle', linklabel='$linklabel', description='$description', keywords='$keywords', pos='$position', pagebody='$pagebody', showing='$visible', lastmodified='now()' WHERE id='$pid'") or die (mysqli_error($myConnection));
}
elseif($oldposition < $position) {
// Hvis en PAGE IKKE skifter subject, men får en HØJERE position, f.eks OP til position 12 FRA position 2
$queryUp = mysqli_query($myConnection, "UPDATE pages SET pos = pos - 1 WHERE pos > $oldposition AND pos <= $position AND subjectid = $subjectid");
$query = mysqli_query($myConnection, "UPDATE pages SET subjectid='$subjectid', pagetitle='$pagetitle', linklabel='$linklabel', description='$description', keywords='$keywords', pos='$position', pagebody='$pagebody', showing='$visible', lastmodified='now()' WHERE id='$pid'") or die (mysqli_error($myConnection));
}
elseif($oldposition = $position) {
// Hvis en PAGE ikke skifter position, foretages en "almindelig" update query
$query = mysqli_query($myConnection, "UPDATE pages SET subjectid='$subjectid', pagetitle='$pagetitle', linklabel='$linklabel', description='$description', keywords='$keywords', pos='$position', pagebody='$pagebody', showing='$visible', lastmodified='now()' WHERE id='$pid'") or die (mysqli_error($myConnection));
}
echo '<div align="center">Operation Completed Successfully! Head back to the admin home page, or the main website to see your changes!<br /><br /><a href="login/admin.php">Click Here For Admin home!</a>
<br /><br /><a href="../" >Or head back to view the live website!</a></div>';
exit();
}
And then my problem appears: If I click the radio button with the value = 0.
The I get gaps in the positions in the database.
1) If a page stays under the same subject, BUT visible (Radio btn) is set to = 0, meaning the page doesnt diaplay - Then the pages whch have a bigger position than the page I just set to visible = 0, doesnt adjust their position, and go 1 position down, where they are bigger than the "visible = 0 page" - I get a gap then.
2) If a page moves to another subject, and get a position etc etc, but I set visible = 0 - then the script actually makes a gap in the positions under the new subject, even thoug the page is not visible. Like the position is reserved.. :-) So even though the page is not visible, the pages under the new subject, adhusts their position as if it was visible!
3) And...lets say admin is editing a page, he lets it stay under the same subject, but moves the position of the page from lets say position 1 to position 4, he fills everything out, but sets visible = 0! - Then the script again makes a gap, and "reserves" that position, even though the page is not showing (visible = 0)
I it a bit hard to explain, but I hope someone have understood my problem and can see how else I can adjust the positions when the radio button with value = 0 is set. Thats the button which decides wheter a page should display or not.
Can I somehow integrate if($visible = '0'){Code here....}
In the above script?
What a story, Hope someone sees it and maybe can help me with this issue :-)