I have written a chunk of code that is aimed at reordering pages.
<form action="process.php" method="post" />
<?php
$apageid = array();
$apagename = 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]'";
$return = $database->query($q);
while($row=mysql_fetch_assoc($return)){
$apageid[] = $row['id'];
$apagename[] = $row['title'];
$apageorder[] = $row['order'];
}
$count = count($pageid);
$bpageid = array();
$bpageorder = array();
//run through each page one at a time and update the order of the menu
for($i=0; $i++; $i<$count){
//set a few variables
$pid = $pageid[$i];
$porder = $pageorder[$i];
?>
<select name="<?php $bpageid[$i] ?>">
<?php
for($j=0; $j++; $j<$count){
?>
<option value="<?php $apageid[$j] ?>"><?php echo $apagename[$j]; ?></option>
<?php
}
?>
</select>
<select name="<?php $bpageorder[$i] ?>">
<?php
for($j=0; $j++; $j<$count){
?>
<option value="<?php $apageorder[$j] ?>"><?php echo $apageorder[$j]; ?></option>
<?php
}
?>
</select>
<?php
}
?>
<input type="submit" name="navigation" value="Reorder pages" />
</form>
For example, if there were 7 menu items, the code should loop through all 7 and display 7 dropdown boxes each with the 7 options within. Next to each dropdown should be the numbers 1-7 which are the order of the boxes. This would allow each dropdown to pick a menu item and assign the order number to it.
Of course, when the script is submitted, I’ll validate that two items don’t clash etc etc.
The code currently isn’t displaying anything but the submit button.
Can anyone see the problem I have?
Thanks
This
$counthere is probably zero because$pageidis never definedAlso, why are you keeping three different arrays for id, title and order? It would probably be clearer if you have everything on a multidimensional array and used foreach loops instead of for.