Forum Moderators: coopster
My menu is constructed via a mysql query that puts the data into an array.
Eg:
mysql_query >
array (
array ('title','link')
array ('title','link')
array ('title','link')
...
)
so on...
So each menu item will have an id, and i have sorted the arrays by their ids so that the menu is listed via the id.
is there a way to (via php, to be included in a cms) make a system to change the ids so that they menu structure could be changed?
[0] => 'something',
[1] => 'somethingelse',
[2] => 'anotherthing';
foreach($array as $key => $value){
$array['number_'.$key] = $value;
unset($array[$key]);
}
print_r($array)would give you:
[number_1] => 'something',... (etc).
[number_2] => 'somethingelse'
In cases like that, especially menu items or other items that we may want to sort by human decision rather than computer code/logic, I have found it beneficial to add a sequence number column to the table itself. Now we can control it's sequence any way we want.
But you are asking "how do I let the end user sort them"? JavaScript is a nice option, or you could display them on the maintenance screen with the menu sequence number and let them change that -- either of the two options, it's your choice and you need to know your intended audience of course ... will they have JavaScript running? If so, it certainly is easy for them to click an item and move it up or down until they get the sequence they want. Then all you have to do is loop through your menu and update sequence numbers.