Jump to content

Displaying menu from mysql by priority


ldrrp

Recommended Posts

i am storing my menu in the database, i want to be able to output it by priority, heres so far what i have. I have no idea were to start. :shrug:

Database dump:

--

-- Table structure for table `menu`

--

CREATE TABLE IF NOT EXISTS `menu` (

  `menu_access_lvl` int(2) NOT NULL,

  `priority` int(11) NOT NULL,

  `name` varchar(200) NOT NULL,

  `comment` text NOT NULL,

  `location` text NOT NULL,

  `creator_id` varchar(255) NOT NULL

) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--

-- Dumping data for table `menu`

--

INSERT INTO `menu` (`menu_access_lvl`, `priority`, `name`, `comment`, `location`, `creator_id`) VALUES

(0, 1, 'Home Page', 'Home page', 'index.php', 'admin'),

(0, 3, 'Contact', 'Contact', 'index.php?PG=contact', 'admin'),

(0, 2, 'Events & Meetings', 'Events & Meetings', 'index.php?PG=events', 'admin'),

(0, 4, 'About', 'About', 'index.php?PG=about', 'admin'),

(2, 5, 'Admin', 'Admin', 'index.php?PG=admin', 'admin');

 

And here is the php code displaying it

 

      //gets the role of the user if set, otherwise role = 0

if(isset($_SESSION['SESS_MEMBER_ID']))$lvl = $_SESSION['SESS_ROLE']; else $lvl = 0;

 

// this loads the menu buttons that correspond to the users role

$menuqry="SELECT * FROM menu WHERE menu_access_lvl<='$lvl'";

$menuresult=mysql_query($menuqry);

 

while($row = mysql_fetch_array($menuresult)){

echo "<li class=\"menuitem\"><a href=\"".$row['location']."\">".$row['name']."</a></li>";

}

 

 

What this currently displays:

Home

Contact

Events & meetings

About

 

I want it to be according to priority in the menu like:

Home

Events & meetings

Contact

About

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.