A solution for ordering menu items in php / mysql

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
mlovelock
Beginner
Beginner
Posts: 4
Joined: Sun Jan 21, 2007 2:47 am

A solution for ordering menu items in php / mysql

Post by mlovelock »

I recently needed to alter the order in which menu items were displayed when pulled out of a mysql database, but couldn't find a solution here on the forums, so I did the following, thought it might be of use to someone:

To my mm_items table, I added the field 'itemorder' (tinyint, or smallint, default = 1 - note this default will place a new item at the front/top of a menu, to place at the bottom, you could use an arbitrary value, say 99 or something)

To mm_phpmenu.php I changed line 323 from this:

Code: Select all

		$query="select * from ".$table_prefix."items where menuid=$mar[menuid]";
to this:

Code: Select all

		$query="select * from ".$table_prefix."items where menuid=$mar[menuid] order by menuid asc, itemorder asc";
It then orders and displays (in ascending order) all menu items according to the 'itemorder' value. It's not rocket science and I'm sure anyone with an ounce or two of mysql/php knowledge has probably already done it, but just thought it might be useful to someone.

Note, I don't think the ordering by menuid is strictly necessarry, but it's just tidy.

Michael.
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Re: A solution for ordering menu items in php / mysql

Post by Ruth »

Thank you very much for posting this information. I sure appreciate any help here on the forum :)

Ruth
Post Reply