Wednesday, August 22, 2012
Create dynamic database-driven CSS navigation menus with Dreamweaver, PHP and MySQL
This article will demonstrate a simple way to create dynamic CSS-based navigation menus that allow you to edit your site navigation across the site with a simple upgrade of the MySQL database. For this example, I use Chrome CSS Drop Down Menu available from Dynamic Drive. This is a free, lightweight CSS menu that is easily customizable and uses only a small amount of JavaScript. There are other free CSS menus available such as the Suckerfish menu and other menu options trading available.
This article assumes that the reader has some familiarity with Dreamweaver, PHP and MySQL. Turning on the navigation menu from a database allows you to easily change navigation of your website by simply updating the database fields that make up the Dreamweaver recordset. Building your site navigation using CSS also allows rapid changes to its site via the stylesheet formatting.
The first step is to implement the CSS menu of your choice. It 's useful to include some menu items as fake style menu so you can see how it will look the navigation menu with multiple choices. Once the menu is OK, go back and delete all but the first menu item in the HTML unordered list.
The second step is to create the MySQL database table, which will power your menu. Using the MySQL manager of your choice, create a table that contains three fields: a unique auto-numbering ID field, a field that contains the text displayed by each menu option, and a hyperlink field, which will include the connection of each menu item follows when clicked. Depending on the structure of the site, you can use relative or absolute URL in this field. At this point, insert the data into the database table to populate the site when it is loaded. For example, in the first row of the table, you could have the menu text "HOME" and "index.php" in the URL.
Then, go back to Dreamweaver to set the dynamic menu. With your page open, establish a connection to the MySQL database and create the menu recordset. Include all database fields and do not use any filters on the data. Returning to the code, find the first menu item that you left behind previously. Highlight the text between the quotation marks after the href portion of code. Go into your control panel and open the recordset associations created for the menu. Click and drag the field representing the field of the URL link in the code where you highlighted the href link. This will create the PHP code to dynamically assign the link for each menu item. Next, highlight the code into your menu item that appears on the browser's text for each menu item. Grab the corresponding recordset binding and drag it into the code. This will create the required PHP code that will dynamically display each menu item.
The last step of the process is to create the repeating region in a loop for each row in the database table. Just highlight all the code from opening to closing tags around them the menu. Go to your server behaviors panel in Dreamweaver and select the "Repeated Region" option. Select correctrecordset for the menu and click the radio button selecting all records. That completes the creation of dynamic menus.
After loading the page on the test server, you can see every menu item that you entered in the database displayed in the menu. The dynamically generated links will all point to the corresponding pages. If you view the page code, you can see makes a clean list for menu items. The code is short and simple and very search engine friendly. For added functionality and the creation of drop-down menu, simply create a database table that includes the sublinks and include a table field that contains the table ID of the parent values. Just filter ID for each main menu option, and dynamically generate the submenu the same way you did the main menu. The menu can be included in a Dreamweaver template for inclusion on every page of your website. When a page is added to the site, simply add the menu item and link to the database and appear on every page that includes the navigation menu. And doesn'tget much easier to create dynamic database-driven CSS menus....
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment