Need help using form to set order of pages on dynamic websit
Posted: Mon Jun 08, 2009 8:34 am
Hi. I went through a tutorial to build a dynamic website in order to facillitate my learning php. One of the steps was to create a simple form so staff members could add new sections for the site. The form includes a Position field, so staff can enter a numeric position for that section to show up in a slist (so a non techy staff member could easily add a Contact Us area and assign it as the second section just by typing Contact Us into the name field of the form and 2 into the position field.
The problem I ran into is that the form does NOT update the positions of other sections that already exist, so you may end up with Products and Contact Us both being assigned to the second position. I'm not sure if I need to use some if / then statements to reassign positions to sections that were already in the database or if there's an array function that will automatically 'slide' the existing sections over so if a new section is designated position 2, all the old sections that had been position 2 or higher will be changed to position n+1.
I've done some reading and worked through a bunch of tutorials, but php is still new to me, so any advice would be much appreciated.
I've pasted some of the code below:
The problem I ran into is that the form does NOT update the positions of other sections that already exist, so you may end up with Products and Contact Us both being assigned to the second position. I'm not sure if I need to use some if / then statements to reassign positions to sections that were already in the database or if there's an array function that will automatically 'slide' the existing sections over so if a new section is designated position 2, all the old sections that had been position 2 or higher will be changed to position n+1.
I've done some reading and worked through a bunch of tutorials, but php is still new to me, so any advice would be much appreciated.
I've pasted some of the code below:
Code: Select all
$id = mysql_prep($_GET['page']);
$menu_name = trim(mysql_prep($_POST['menu_name']));
$position = mysql_prep($_POST['position']);
$visible = mysql_prep($_POST['visible']);
$content = mysql_prep($_POST['content']);
//Database submission only proceeds if there were NO errors.
if(empty($errors)){
$query = "UPDATE pages SET
menu_name = '{$menu_name}',
position = {$position},
visible = {$visible},
content = '{$content}'
WHERE id = {$id}";
$result = mysql_query($query, $connection);