Jump to content

Show javascript menu based on sql table results


WAMFT1

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>';
?>

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.

Archived

This topic is now archived and is closed to further replies.

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