CodersAdvocate

I work hard, so you don't have to

Custom navigation with PHP

 

Today i'm going to talk about custom navigation menus behind the login infrastructure i discussed in a previous tutorial.

When we need to give out accesses to the users of a site, the first thing we need to do is work out a mechanism. An ideal infrastructure for this is to store an access right in the table which holds the users information.

so tblUsers now looks like this...

tblUsers(UserID,Firstname,Surname,Login,Password,AccessID)

You can see we have another ID in here which means we need another table. One which we can call tblAccess. Which will look like this,

tblAccess(AccessID, Description)

Take the following two tables,

tblUsers
UserID Firstname Surname Login Password AccessID
1 Bill Gates bg001 **** 1
2 Matt Cutts mc001 **** 2
3 Tony Blair tb001 **** 1
AND
tblAccess
AccessID Description
1 Full
2 ReadOnly
3 Blocked

Now for some php.
Start off by desiging your navigation system, for mine i will be using ul tags.

< ul >
< li >< a href="#" >Home< /a >< /li >
< li >< a href="#" >View details< /a >< /li >
< li >< a href="#" >Edit details< /a >< /li >
< li >< a href="#" >View clients< /a >< /li >
< li >< a href="#" >Edit Clients< /a >< /li >
< /ul >

Now a bit of mySql to pull out the information needed to filter out the navigation.
Select * from tblUsers Where ID = $_SESSION['userID']
if we put that in a record set, say "rsCurrentUser", we can the use that object to fiter out the navi menu. Lets re visit the navigation

< ?php
$AccessID = mysql_result($rsCurrentUser,0,"AccessID");
? >
< ul >

< ?php
if ($AccessID = 1 || $AccessID = 2){
? >

< li >< a href="#" >Home< /a >< /li >

< ?php
}
? >


< ?php
if ($AccessID = 1 || $AccessID = 2){
? >

< li >< a href="#" >View details< /a >< /li >

< ?php
}
? >


< ?php
if ($AccessID = 1){
? >

< li >< a href="#" >Edit details< /a >< /li >

< ?php
}
? >


< ?php
if ($AccessID = 1 || $AccessID = 2){
? >

< li >< a href="#" >View clients< /a >< /li >

< ?php
}
? >



< ?php
if ($AccessID = 1){
? >

< li >< a href="#" >Edit Clients< /a >< /li >

< ?php
}
? >

< /ul >

Hopefully that will put you on the right track to start making custom navigations for the users of your site.

Copyright 2011 CodersAdvocate ©