(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:
Website Builder for Churches, Authors, Consultants, Magazines Website Builder for Beginners, Bloggers, Writers, IT Companies  |  Website Builder for nonprofits and therapists  |  Best Website Builder for Education, Software Companies, Designers, Videos  |  Website Builder for Online Stores, Restaurants, Musicians, Real Estate  |  Best Website Builder for podcasts and affiliate marketing  | 
Copyright (c) 2019, Deluxe-Menu.com
Home  |  Product Info  |  Samples  |  Download  |  Purchase  |  FAQ  |  Site Map  |  Terms of Use  |  Write Us
All rights reserved. Free AI Website Builder | AI Website Builder | Free AI Website Builder | Website Generator AI | AI website design generator