I have written a script that allows me to reorder items on a menu.
The code selects (to display), the title of the page and the order in which the page appears on the menu.
For example, if there are 5 pages (About Us, Mission & Vision, Awards, Environmental Policy, Locations), the order will be 1-5.
As you can see from the screenshot, the code generates 5 dropdowns all with the 5 page options. On the other dropdown, you get 1-5.
What I'm trying to do is get the menu to load the names and page order that the menu is already in straight into that form.
So each dropdown will have a page title and the corresponding order in the other dropdown. The user would then be able to change this if needed.
How could I change my code to achieve this?
<?php
$apageid = array();
$apagename = array();
$apageorder = array();
$q = "SELECT g.id, g.title, n.order FROM tbl_general g INNER JOIN tbl_navigation n ON n.pageid = g.id WHERE n.type = '$_SESSION[parent]' ORDER BY n.order";
$return = $database->query($q);
while($row=mysql_fetch_assoc($return)){
$apageid[] = $row['id'];
$apagename[] = $row['title'];
$apageorder[] = $row['order'];
}
$count = count($apageid);
$bpageid = array();
$bpageorder = array();
?>
<div class="form-holder">
<?php
//run through each page one at a time and update the order of the menu
for($i=0; $i<$count; $i++){
?>
<div class="form-row">
<div class="form-label">
Page Name
</div>
<div class="form-field">
<select class="select-small" name="<?php echo $bpageid[$i] ?>">
<?php
for($j=0; $j<$count; $j++){
?>
<option value="<?php echo $apageid[$j]; ?>"><?php echo $apagename[$j]; ?></option>
<?php
}
?>
</select>
<select class="select-small" name="<?php echo $bpageorder[$i] ?>">
<?php
for($k=0; $k<$count; $k++){
?>
<option value="<?php echo $apageorder[$k]; ?>"><?php echo $apageorder[$k]; ?></option>
<?php
}
?>
</select>
</div>
</div>
<?php
}
?>