WAMFT1 Posted January 22, 2014 Share Posted January 22, 2014 Hi Guys I am wanting to create a menu page which displays menu's based on if the menu field in the sql database has a yes or no in the contents by using an if statement. I have not had much success and would like some help to point me in the right direction. <?php include("../edb.php"); $id =$_REQUEST['id']; $result=mysql_query("SELECT * FROM `eusers` WHERE id='".$_SESSION['uid']."'"); if($MENUAdviser="Y") echo '<script type="text/javascript" src="ExtranetMenu.js"></script>'; if($MENUPAS="Y") echo '<script type="text/javascript" src="PASMenu.js"></script>'; if($MENUStaff="Y") echo '<script type="text/javascript" src="IntranetMenu.js"></script>'; if($MENUWebAdmin="Y") echo '<script type="text/javascript" src="WebAdminMenu.js"></script>'; ?> Link to comment https://forums.phpfreaks.com/topic/285581-show-javascript-menu-based-on-sql-table-results/ Share on other sites More sharing options...
Mace Posted January 22, 2014 Share Posted January 22, 2014 After setting the mysql_query you still have to call a mysql_fetch function with the result. use for an example: http://nl3.php.net/manual/en/function.mysql-fetch-assoc.php $result=mysql_query("SELECT * FROM `eusers` WHERE id='".$_SESSION['uid']."'"); while ($row = mysql_fetch_assoc($result)) { if($row['MENUAdviser']=="Y"){ echo '<script type="text/javascript" src="ExtranetMenu.js"></script>'; } if($row['MENUPAS']=="Y"){ echo '<script type="text/javascript" src="PASMenu.js"></script>'; } if($row['MENUStaff']=="Y"){ echo '<script type="text/javascript" src="IntranetMenu.js"></script>'; } if($row['MENUWebAdmin']=="Y"){ echo '<script type="text/javascript" src="WebAdminMenu.js"></script>'; } } Also, if you use if statements. Use the == operator instead of a single =. Otherwise it wont work. Link to comment https://forums.phpfreaks.com/topic/285581-show-javascript-menu-based-on-sql-table-results/#findComment-1466159 Share on other sites More sharing options...
WAMFT1 Posted January 22, 2014 Author Share Posted January 22, 2014 Awesome, thanks for your help Mace. Working like a charm. Link to comment https://forums.phpfreaks.com/topic/285581-show-javascript-menu-based-on-sql-table-results/#findComment-1466164 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.