Solved

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

Posted on 2016-09-15
3
56 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:Caracena
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:Caracena
ID: 41800419
Didn't thought it would make much sense but now that I read your response it totally made sense!
0
 
LVL 54

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
array_values - reorder after unset? 5 21
How to count in a table in php 22 35
Is there a limit to how many inner joins you should use? 4 31
AWS EC2 & RDS Instance 5 35
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

773 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