954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

PHP/mySQL dynamic single-level menu

Hi there,
I have built a simple CMS that is generally working well, the issue I'm having is with building dynamic navigation.

On the site the content for the individual pages is fine but getting the menu data and creating the menus is causing problems.

I have 2 possible structures that the database is already set up for, the first is calling all data out of a single table; the second is to call page content from the 'pages' table and menu data from the 'menu' table.

Regardless what way I'm calling the data I cannot all of the required data out of mySQL.

Working mySQL code:

$query = mysql_query("SELECT * FROM pages WHERE sefurl='$url'")
   or die ("I have a problem getting the information you requested"); 
   $data = mysql_fetch_array($query);
   $title = $data[title];
   $content = $data[content];


I hae re-written the mySQL query a number of ways however it constantly dies.

The menus on the site that is demanding the dynamic menus are mainMenu and productMenu, there is a colum in mySQL called menu type to handle this and seperate the menus.

I appreciate your help!

centralpulse
Newbie Poster
2 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

It took me around 10 hours but the winning code is, DRUM ROLL PLEASE...

$query = mysql_query("SELECT * FROM pages WHERE sefurl='$url'")
   or die ("I have a problem getting the information you requested"); 
   $data = mysql_fetch_array($query);
   $title = $data[title];
   $content = $data[content];
   	
mysql_free_result($query);

   $query = mysql_query("SELECT * FROM menu ORDER BY menuOrder ASC")
    or die ("I have a problem getting the information you requested"); 
	while($row = mysql_fetch_array($query))
   {
	  list($sefurl, $menuType, $menuName, $menuOrder) = $row;
	  if($menuType == "mainMenu") {
      $mainMenu .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font class=\"mainMenu\"><a href=\"$sefurl.html\">$menuName</a></font>\n";
	  }
	  if($menuType == "productMenu") {
      $productMenu .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font class=\"mainMenu\"><a href=\"$sefurl.html\">$menuName</a></font>\n";
	  }
centralpulse
Newbie Poster
2 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: