Solved

What is the most practical way to display items based in each user level?

Posted on 2016-09-15
3
75 Views
Last Modified: 2016-09-16
Hello,

I'm trying to figure out how to build a menu that will show more or less elements based on each user level in PHP.

I'm currently naming user levels in the DB as "Admin", "User", "Special" and so on. What I need is for the Admin to see all elements, the user to see some elements and so on. I could do lots of IF statements but maybe there's a quick way to do it in a function or something?

Thanks in advance!
0
Comment
Question by:Cesar Aracena
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 500 total points
ID: 41800390
An alternative to creating a menu with many if statements is to create 3 menus in 3 separate files, let's say menu_admin.php, menu_user.php and menu_special.php, then include the right file depending on the logged user level.
0
 
LVL 6

Author Closing Comment

by:Cesar Aracena
ID: 41800419
Didn't thought it would make much sense but now that I read your response it totally made sense!
0
 
LVL 58

Expert Comment

by:Julian Hansen
ID: 41801266
Usually menu systems like this are created dynamically. You have a data structure in which the menu items and user access are stored which is used to construct the menu - the data structure is usually (but does not have to be) sourced from a database query that joins available menu items to users based on an access_rights table linking users to menu items.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question