| 
       
          
                    I�d like to know how  to populate the navigation bar menu from a database?
       
      Return to Recent Questions
 
  
Q: 
I�d like to know how  to populate the navigation bar menu from a database?
 
  
A:
Please, see the example of .php file.
The content of .php file depends on your database structure. 
  
<?php 
  
// The example for PHP/MySQL.  
// MySQL database has the table "menuTable" that contains data for menu items.  
// The table has the following fields:  
// 1. "text" - item text  
// 2. "link" - item link  
// 3. "icon1" - item icon (normal state)  
// 4. "icon2" - item icon (mouseover state)  
function getMenuItems() 
{  
$jsItems = ''; 
  
// Select all records from table "menuTable"  
$allItems = mysql_query('SELECT * FROM menuTable;'); 
  
// Extract items data from database and build Javascript code for menuItems  
while ($itemData=mysql_fetch_array($allItems))  
{  
$jsItems .= '["'.$itemData['text'].'", "'.$itemData['link'].'", "'.$itemData['icon1'].'", "'.$itemData['icon2'].'"],';  
} 
  
// Return Javascript code  
return $jsItems;  
} 
  
 
?>
   
<script>  
var menuParam1 = value1;  
var menuParam2 = value2;  
var menuParam2 = value2;  
... 
  
var menuItems = [ 
  
// Write Javascript code for menu items  
echo getMenuItems();  
 
?> 
  
];  
</script> 
  
 
 
  
Return to Recent Questions
           Related: 
         
         - Sep 26, 2006 - Why is the submenu has a different colour than menu items in the javascript menu bar?
 - Sep 30, 2006 - The frame below the javascript menubar is moved to the bottom of the page.
 - Oct 12, 2006 - Can I create a scroll vertical menu on the right side and the subnav popout on the LEFT?
 - Nov 06, 2006 - Each item is a different width. Can I do this with your html navigation bar?...
 - Nov 10, 2006 - I want to set the status bar messages to another than the link text from the xp menu items?
 - Nov 12, 2006 - Is this menu bar code compatible under Linux?
 - Nov 29, 2006 - Why the  background images disappear for a while after hovering over html menubar?
 - Nov 30, 2006 - How to select the font and backcolors in java menubar using the hexidecimal number?
 - Dec 04, 2006 - When running navigation bar code with IE or Firefox, the background is  transparent.
 - Dec 04, 2006 - With the licensed .js files of menu dhtml the status bar on IE shows "Error on page".
 - Dec 06, 2006 - Is using search engine friendly code the same as using normal html menu bar for spiders?
           
               
   |