Jump to content

Show javascript menu based on sql table results


WAMFT1
Go to solution Solved by Mace,

Recommended Posts

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
Share on other sites

  • Solution

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
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.