Home arrow MySQL arrow Page 6 - Building a Simple ColdFusion Content Management System with MySQL

Breadcrumb List - MySQL

This tutorial lays out the basics for creating a content management system in ColdFusion and MySQL. The System leverages hierarchical data to automatically build breadcrumb lists, a side navigation menu, as well as a site map. The goal of this tutorial is to provide a framework upon which to build a content management system that is easy to customize and maintain, leaving the web author more time to create content than maintain code.

  1. Building a Simple ColdFusion Content Management System with MySQL
  2. Starting With MySQL
  3. The Page and how to Update/Modify and Delete
  4. Add/Modify Form
  5. Action
  6. Breadcrumb List
  7. Side Menu
  8. Site Map
By: Charles Kaufmann
Rating: starstarstarstarstar / 48
August 11, 2004

print this article



Breadcrumb lists are useful for many people that may be navigating your site. As they click deeper in your site, they often would like to go back up the hierarchy of it or simply go back to the home page. We are going to create a new page (you can call it whatever you want but for this tutorial I will name if Breadcrumb.cfm) for the breadcrumb code, then CFINCLUDE it into the top of the page after the CFQUERY for the page. So on a new ColdFusion template add the following.

1   <!--- Bread Crumb --->
2   <cfset breadcrumblist = "">
3   <cfloop list="#getpage.hierarchy#" delimiters="~" index="i">
4     <cfquery name="breadcrumb2" datasource="#variables.data#">
5       select *
6       From tblpages
7       Where id = #i# and status='A'
8    </cfquery>
9    <cfset breadcrumblist = #breadcrumblist# &
10  ' &gt; <a href="page.cfm?id=#breadcrumb2.id#" target="_self">
11  #breadcrumb2.title#</a>'>
12  </cfloop>
14  <cfif listlen(breadcrumb.hierarchy, "~") gt 1>
15   <cfset baseid = #listgetat(breadcrumb.hierarchy, 2, "~")#>
16  <cfelse>
17   <cfset baseid = 1>
18  </cfif>
20  <cfoutput>#variables.breadcrumblist#</cfoutput>
21  <!--- Bread Crumb --->

Now let's walk through it. Line 2 sets a variable that will contain the list. Line 3 starts the CFLOOP that will loop through the HIERARCHY field that we have built on the record add action previously discussed. Since we already ran the CFQUERY for the current page, we can use the results in the CFLOOP. We are going to loop through the hierarchy list to query out the title of all the pages that will be shown on the breadcrumb list. Lines 4 through 8 query the records every time through the loop using the value in the hierarchy list to query out the ID of the record. Lines 9 through 11 add to the breadcrumb list variable with all the HTML markup so people can click on the link to bring them to the page.

Lines 14 through 18 set a variable called "Baseid". This variable will be used for the menu that will be explained in the next section. The menus I will be building next will be based on the HIERARCHY field. The menu may get rather long if it displays all of the pages within the site (if the site you are building is going to get large). What I am trying to accomplish with the Baseid variable is to determine what section of the site you are at. I am trying to get the ID of the second level page, which would be pages that are the children of the home page. Line 14 starts a CFIF statement that checks to see if the hierarchy list is greater than 1 (not the home page). If the CFIF is true, then it CFSET's the baseid variable to the second number in the hierarchy list. Line 16 and 17 catch the false value and CFSETS the baseid to 1 because it is the homepage. Line 20 simply outputs the breadcrumb list on the page.

>>> More MySQL Articles          >>> More By Charles Kaufmann

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Oracle Unveils MySQL 5.6
- MySQL Vulnerabilities Threaten Databases
- MySQL Cloud Options Expand with Google Cloud...
- MySQL 5.6 Prepped to Handle Demanding Web Use
- ScaleBase Service Virtualizes MySQL Databases
- Oracle Unveils MySQL Conversion Tools
- Akiban Opens Database Software for MySQL Use...
- Oracle Fixes MySQL Bug
- MySQL Databases Vulnerable to Password Hack
- MySQL: Overview of the ALTER TABLE Statement
- MySQL: How to Use the GRANT Statement
- MySQL: Creating, Listing, and Removing Datab...
- MySQL: Create, Show, and Describe Database T...
- MySQL Data and Table Types
- McAfee Releases Audit Plugin for MySQL Users

Developer Shed Affiliates


Dev Shed Tutorial Topics: