(c) 2016, Deluxe-Menu.com
Search  
Ctrl+F2 - enter/switch menu | Arrow keys - navigate | Esc - exit menu  
  Support
  FAQ
  Contacts
  About Us
  Recent Questions


 

    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:
First-rate Easy Website Builder | How-to Guide Fantastic Bootstrap Page Themes For Your Company  |  Great MP4 to HTML5 Generator Tutorial  |  Reputable Drag and Drop Web Builder | Overview  |  Fine Responsive Web Page Builder | Overview  |  Effective Web Page Design Tools  | 
Copyright (c) 2019, Deluxe-Menu.com
Home  |  Product Info  |  Samples  |  Download  |  Purchase  |  FAQ  |  Site Map  |  Terms of Use  |  Write Us
All rights reserved. AI Website Builder | AI Website Maker | AI Website Generator | Website Generator AI | AI web page design generator