<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Website Design, Search Engine Optimization &amp; Internet Marketing</title>
	
	<link>http://wizardinternetsolutions.com</link>
	<description>Wizard Internet Solutions</description>
	<lastBuildDate>Thu, 03 May 2012 05:16:25 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/WizardInternetSolutions" /><feedburner:info uri="wizardinternetsolutions" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>A PHP class to build parent child arrays from a flat array or database query results.</title>
		<link>http://feedproxy.google.com/~r/WizardInternetSolutions/~3/kQnMurg2QZw/</link>
		<comments>http://wizardinternetsolutions.com/web-database-design/a-php-class-to-build-parent-child-arrays-from-a-flat-array-or-database-query-results/#comments</comments>
		<pubDate>Thu, 03 May 2012 05:10:45 +0000</pubDate>
		<dc:creator>danieliser</dc:creator>
				<category><![CDATA[Web & Database Design]]></category>

		<guid isPermaLink="false">http://wizardinternetsolutions.com/?p=1573</guid>
		<description><![CDATA[<p>I am currently developing using Kohana 3.2 PHP Framework incorporating Mustache Templates and the Twitter Bootstrap with LESS CSS and loving it. I recently wrote this simple php class to convert a flat array with id and parent_id keys into a multi-dimensional array where parents have a `children` key with children in a sub-array. class [...]</p><p><a href="http://wizardinternetsolutions.com/web-database-design/a-php-class-to-build-parent-child-arrays-from-a-flat-array-or-database-query-results/">A PHP class to build parent child arrays from a flat array or database query results.</a>
<a href="http://wizardinternetsolutions.com">Website Design, Search Engine Optimization &amp; Internet Marketing - Wizard Internet Solutions</a></p>]]></description>
				<content:encoded><![CDATA[<p>I am currently developing using Kohana 3.2 PHP Framework incorporating Mustache Templates and the Twitter Bootstrap with LESS CSS and loving it. I recently wrote this simple php class to convert a flat array with id and parent_id keys into a multi-dimensional array where parents have a `children` key with children in a sub-array.</p>
<pre class="brush:php">class BuildParentChild {

	private $data = array();
	public $rendered;

	public function __construct(&amp;$Input)
	{
		foreach($Input as $Item)
		{
			$Item= (array) $Item;
			$this-&gt;data['items'][$Item['id']] = $Item;
			$this-&gt;data['parents'][$Item['parent_id']][] = $Item['id'];
			if(!isset($this-&gt;top_level) || $this-&gt;top_level &gt; $Item['parent_id'])
			{
				$this-&gt;top_level = $Item['parent_id'];
			}
		}
		return $this;
	}

	public function build($id)
	{
		$return{$id} = array();
		foreach($this-&gt;data['parents'][$id] as $child)
		{
			$build = $this-&gt;data['items'][$child];
			if(isset($this-&gt;data['parents'][$child]))
			{
				$build['has_children'] = true;
				$build['children'] = $this-&gt;build($child);
			}
			else
			{
				$build['has_children'] = false;
			}
			$return{$id}[] = $build;
		}
		return (array) $return{$id};
	}

	public function render()
	{
		if(!isset($this-&gt;rendered) || !is_array($this-&gt;rendered))
		{
			$this-&gt;rendered = $this-&gt;build($this-&gt;top_level);
		}
		return $this-&gt;rendered;
	}
}

$Menu = new BuildParentChild($menu_items);
var_dump($Menu-&gt;render());</pre>
<p>If you put in rows like<br />
id &#8211; parent_id &#8211; name<br />
1 &#8211; 0 &#8211; Top<br />
2 &#8211; 1 &#8211; Second Level<br />
3 &#8211; 2 &#8211; Third Level<br />
4 &#8211; 1 &#8211; Another Second Level<br />
5 &#8211; 0 &#8211; Another Top Level</p>
<p>You would recieve</p>
<pre class="brush:php">array(
  'id' => 1,
  'name' => top,
  'has_children' => true,
  'children' => array(
    array(
      'id' => 2,
      'name' => Second Level,
      'has_children' => true,</pre>
<p>and so on.</p>
<h4>Incoming search terms:</h4><ul class="search-terms"><li>php mysql parent child array</li><li>php menu class</li><li>php class menu</li><li>php parent child array</li><li>database design for search engine</li><li>php multimlevel</li><li>class category php</li><li>mysql parent child</li><li>php and mysql navigation menu class</li><li>make php menu from categories</li><li>php mysql search display results script with chind menu</li><li>php mysql array parent id</li></ul><p><a href="http://wizardinternetsolutions.com/web-database-design/a-php-class-to-build-parent-child-arrays-from-a-flat-array-or-database-query-results/">A PHP class to build parent child arrays from a flat array or database query results.</a>
<a href="http://wizardinternetsolutions.com">Website Design, Search Engine Optimization &amp; Internet Marketing - Wizard Internet Solutions</a></p><img src="http://feeds.feedburner.com/~r/WizardInternetSolutions/~4/kQnMurg2QZw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://wizardinternetsolutions.com/web-database-design/a-php-class-to-build-parent-child-arrays-from-a-flat-array-or-database-query-results/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://wizardinternetsolutions.com/web-database-design/a-php-class-to-build-parent-child-arrays-from-a-flat-array-or-database-query-results/</feedburner:origLink></item>
		<item>
		<title>Thematic Header Image The Right Way!</title>
		<link>http://feedproxy.google.com/~r/WizardInternetSolutions/~3/7AvmrX4Newk/</link>
		<comments>http://wizardinternetsolutions.com/thematic/thematic-header-image-way/#comments</comments>
		<pubDate>Fri, 15 Oct 2010 17:56:41 +0000</pubDate>
		<dc:creator>danieliser</dc:creator>
				<category><![CDATA[Thematic]]></category>
		<category><![CDATA[Change]]></category>
		<category><![CDATA[cursor pointer]]></category>
		<category><![CDATA[header image]]></category>
		<category><![CDATA[image function]]></category>
		<category><![CDATA[logo]]></category>
		<category><![CDATA[logo image]]></category>
		<category><![CDATA[position]]></category>
		<category><![CDATA[span id]]></category>
		<category><![CDATA[theme]]></category>

		<guid isPermaLink="false">http://wizardinternetsolutions.com/?p=608</guid>
		<description><![CDATA[<p>This method is by far the best method. It keeps all the SEO optimized Thematic code and it simply adds an empty span to the header and styles it. </p><p><a href="http://wizardinternetsolutions.com/thematic/thematic-header-image-way/">Thematic Header Image The Right Way!</a>
<a href="http://wizardinternetsolutions.com">Website Design, Search Engine Optimization &amp; Internet Marketing - Wizard Internet Solutions</a></p>]]></description>
				<content:encoded><![CDATA[<p>I have been working with the <span class="removed_link" title="http://themeshaper.com/thematic/">Thematic</span> theme for wordpress for about a week and love it. After reading many ways to add a header image i found most methods lacking. Some replaced the entire header with a single image, others just removed the blog title and description, ie. also removing the<br />
&lt;h1&gt; tags from the homepage.</p>
<p>This method is by far the best method. It keeps all the SEO optimized Thematic code and it simply adds an empty span to the header and styles it.</p>
<p>Add this to your Child Themes Functions.php</p>
<pre class="brush:php">// Add Header Image // Add Header Image
function thematic_logo_image() {
 echo '&lt;a href="'.get_bloginfo('url').'" title="'.get_bloginfo('name').'" &gt;&lt;span id="header-image"&gt;&lt;/span&gt;&lt;/a&gt;';
}
add_action('thematic_header','thematic_logo_image',6);</pre>
<p>Add this to your Child Themes style.css and make any changes necessary.</p>
<pre class="brush:css">#branding {
 height: 187px; /* Change this to your images height */
 padding: 0;
 position:relative;
}
#header-image {
 background:url("images/header.jpg") no-repeat transparent; /* Change This to Your Image */
 height:100%;
 width:100%;
 position:absolute;
 cursor: pointer;
 top:0;
}</pre>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/pixy.gif?x-id=4f513c61-909f-4a95-8c1b-1e6ff85b343a" alt="" /></div>
<h4>Incoming search terms:</h4><ul class="search-terms"><li>header images for websites</li><li>thematic header image</li><li>thematic header</li><li>thematic_header</li><li>function thematic_logo_image</li><li>image for header of website</li><li>thematic_header()</li><li>transparent header image for twenty eleven</li><li>website header images</li><li>website transparent header</li><li>web header image</li><li>website header image</li></ul><p><a href="http://wizardinternetsolutions.com/thematic/thematic-header-image-way/">Thematic Header Image The Right Way!</a>
<a href="http://wizardinternetsolutions.com">Website Design, Search Engine Optimization &amp; Internet Marketing - Wizard Internet Solutions</a></p><img src="http://feeds.feedburner.com/~r/WizardInternetSolutions/~4/7AvmrX4Newk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://wizardinternetsolutions.com/thematic/thematic-header-image-way/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		<feedburner:origLink>http://wizardinternetsolutions.com/thematic/thematic-header-image-way/</feedburner:origLink></item>
		<item>
		<title>Using Child Themes with Artisteer sidebar templates.</title>
		<link>http://feedproxy.google.com/~r/WizardInternetSolutions/~3/tMKQ9EdjJaQ/</link>
		<comments>http://wizardinternetsolutions.com/artisteer/child-themes-artisteer-sidebar-templates/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 22:14:17 +0000</pubDate>
		<dc:creator>danieliser</dc:creator>
				<category><![CDATA[Artisteer]]></category>
		<category><![CDATA[check]]></category>
		<category><![CDATA[Child]]></category>
		<category><![CDATA[css stylesheet]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[parent]]></category>
		<category><![CDATA[php scripts]]></category>
		<category><![CDATA[sidebars]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[template files]]></category>
		<category><![CDATA[theme]]></category>

		<guid isPermaLink="false">http://wizardinternetsolutions.com/?p=581</guid>
		<description><![CDATA[<p>I have been using artisteer to create the basic templates for some of my sites. With the release of WordPress 3.0 came many features. One that i like and have been learning to use is Child Themes. These are great for artisteer themes as i can make many changes to the child theme and if [...]</p><p><a href="http://wizardinternetsolutions.com/artisteer/child-themes-artisteer-sidebar-templates/">Using Child Themes with Artisteer sidebar templates.</a>
<a href="http://wizardinternetsolutions.com">Website Design, Search Engine Optimization &amp; Internet Marketing - Wizard Internet Solutions</a></p>]]></description>
				<content:encoded><![CDATA[<p>I have been using <a class="zem_slink" title="Artisteer" rel="homepage" href="http://www.artisteer.com/" target="_blank">artisteer</a> to create the basic templates for some of my sites. With the release of WordPress 3.0 came many features. One that i like and have been learning to use is Child Themes. These are great for artisteer themes as i can make many changes to the child theme and if i update the parent theme the childs changes are carried over automatically. for more info on this check out the WP Codex or one of the many tutorials available on google. The problem with this is that artisteers templates need a quick change to make them compatible.</p>
<p>I found this problem when trying to use sidebar1.php in my child theme to replace the parents sidebar. The problem lies in how the artisteer template calls the sidebars. It uses the WP &#8220;TEMPLATEPATH&#8221; to load the php scripts. When using a child theme this creates a problem as TEMPLATEPATH points to the parent themes directory. To get sidebars to load from the current theme(child theme if selected) you need to search for TEMPLATEPATH in all your parent template files and replace it with STYLESHEETPATH which points to the directory of the current themes <a class="zem_slink" title="Style sheet (web development)" rel="wikipedia" href="http://en.wikipedia.org/wiki/Style_sheet_%28web_development%29" target="_blank">CSS stylesheet</a>.</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/pixy.gif?x-id=3165faf8-6a78-4e27-bbc7-e2845da452b5" alt="" /></div>
<h4>Incoming search terms:</h4><ul class="search-terms"><li>artisteer templates</li><li>artisteer child theme</li><li>Artisteer ebay</li><li>artisteer portfolio template</li><li>ebay templates artisteer</li></ul><p><a href="http://wizardinternetsolutions.com/artisteer/child-themes-artisteer-sidebar-templates/">Using Child Themes with Artisteer sidebar templates.</a>
<a href="http://wizardinternetsolutions.com">Website Design, Search Engine Optimization &amp; Internet Marketing - Wizard Internet Solutions</a></p><img src="http://feeds.feedburner.com/~r/WizardInternetSolutions/~4/tMKQ9EdjJaQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://wizardinternetsolutions.com/artisteer/child-themes-artisteer-sidebar-templates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://wizardinternetsolutions.com/artisteer/child-themes-artisteer-sidebar-templates/</feedburner:origLink></item>
		<item>
		<title>Single Query Dynamic Multi-level Menu</title>
		<link>http://feedproxy.google.com/~r/WizardInternetSolutions/~3/HSyUxFwi4JQ/</link>
		<comments>http://wizardinternetsolutions.com/web-database-design/single-query-dynamic-multi-level-menu/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 06:04:51 +0000</pubDate>
		<dc:creator>danieliser</dc:creator>
				<category><![CDATA[Web & Database Design]]></category>
		<category><![CDATA[link]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[menu table]]></category>
		<category><![CDATA[multidimensional array]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[parent menu]]></category>
		<category><![CDATA[Query]]></category>
		<category><![CDATA[result]]></category>
		<category><![CDATA[root function]]></category>
		<category><![CDATA[sql results]]></category>

		<guid isPermaLink="false">http://wizardinternetsolutions.com/?p=341</guid>
		<description><![CDATA[<p>Dynamic Multi Level Menus using only a single query. This is a simple PHP function that pulls a Multi-level menu from a MySQL table. You can easily adapt to any CSS style.</p><p><a href="http://wizardinternetsolutions.com/web-database-design/single-query-dynamic-multi-level-menu/">Single Query Dynamic Multi-level Menu</a>
<a href="http://wizardinternetsolutions.com">Website Design, Search Engine Optimization &amp; Internet Marketing - Wizard Internet Solutions</a></p>]]></description>
				<content:encoded><![CDATA[<p>Since writing <a title="Permanent Link to Dynamic Multi-level CSS Menu  with PHP and MySQL. SEO Ready." href="../dynamic-multilevel-css-menu-php-mysql/" rel="bookmark">Dynamic Multi-level CSS Menu with PHP and MySQL. SEO Ready</a> I have learned quite a lot and in doing so found a much more efficient way of building this menu. This method varies in that it only makes one query to the menu table and compiles the results into a multidimensional array. The basic recurring function was just about the same, just taking into account the changes in data structure. Lets start with the query and array.</p>
<pre class="brush:php">// Select all entries from the menu table
$result=mysql_query("SELECT id, label, link, parent FROM menu ORDER BY parent, sort, label");
// Create a multidimensional array to conatin a list of items and parents
$menu = array(
    'items' =&gt; array(),
    'parents' =&gt; array()
);
// Builds the array lists with data from the menu table
while ($items = mysql_fetch_assoc($result))
{
    // Creates entry into items array with current menu item id ie. $menu['items'][1]
    $menu['items'][$items['id']] = $items;
    // Creates entry into parents array. Parents array contains a list of all items with children
    $menu['parents'][$items['parent']][] = $items['id'];
}</pre>
<p>The $menu contains 2 other arrays, items holds every result from the menu table query, the parents array holds a list of all item ids that have children. Next we use a while statement to run through the sql results and assign items to the arrays. If the items parent id already exists in the parents array it will be overwritten so there will only be 1 of each parent id listed.</p>
<pre class="brush:php">// Menu builder function, parentId 0 is the root
function buildMenu($parent, $menu)
{
   $html = "";
   if (isset($menu['parents'][$parent]))
   {
      $html .= "
      &lt;ul&gt;\n";
       foreach ($menu['parents'][$parent] as $itemId)
       {
          if(!isset($menu['parents'][$itemId]))
          {
             $html .= "&lt;li&gt;\n  &lt;a href='".$menu['items'][$itemId]['link']."'&gt;".$menu['items'][$itemId]['label']."&lt;/a&gt;\n&lt;/li&gt; \n";
          }
          if(isset($menu['parents'][$itemId]))
          {
             $html .= "
             &lt;li&gt;\n  &lt;a href='".$menu['items'][$itemId]['link']."'&gt;".$menu['items'][$itemId]['label']."&lt;/a&gt; \n";
             $html .= buildMenu($itemId, $menu);
             $html .= "&lt;/li&gt; \n";
          }
       }
       $html .= "&lt;/ul&gt; \n";
   }
   return $html;
}
echo buildMenu(0, $menu);</pre>
<p>This version signifigantly reduces the strain on your server if you have hundreds or thousands of pages and still allows you to keep a completely dynamic menu.</p>
<h4>Incoming search terms:</h4><ul class="search-terms"><li>php mysql multi level menu</li><li>multi level accordion menu</li><li>multi level menu in php</li><li>php multi level menu database</li><li>php multi level categories</li><li>dynamic multi-level css menu with php and mysql</li><li>select a name as parent b name as child from menus as a menus as b where a id = b parent_id</li><li>dynamic multi level menu</li><li>search engine database design</li><li>multi level category php</li><li>multi level menu</li><li>php accordion menu</li></ul><p><a href="http://wizardinternetsolutions.com/web-database-design/single-query-dynamic-multi-level-menu/">Single Query Dynamic Multi-level Menu</a>
<a href="http://wizardinternetsolutions.com">Website Design, Search Engine Optimization &amp; Internet Marketing - Wizard Internet Solutions</a></p><img src="http://feeds.feedburner.com/~r/WizardInternetSolutions/~4/HSyUxFwi4JQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://wizardinternetsolutions.com/web-database-design/single-query-dynamic-multi-level-menu/feed/</wfw:commentRss>
		<slash:comments>47</slash:comments>
		<feedburner:origLink>http://wizardinternetsolutions.com/web-database-design/single-query-dynamic-multi-level-menu/</feedburner:origLink></item>
		<item>
		<title>Ebay style search menu with category totals count displayed.</title>
		<link>http://feedproxy.google.com/~r/WizardInternetSolutions/~3/2cToF-25_os/</link>
		<comments>http://wizardinternetsolutions.com/web-database-design/ebay-style-search-menu-category-totals-count-displayed/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 06:35:38 +0000</pubDate>
		<dc:creator>danieliser</dc:creator>
				<category><![CDATA[Web & Database Design]]></category>
		<category><![CDATA[count]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[demo data]]></category>
		<category><![CDATA[ebay]]></category>
		<category><![CDATA[link]]></category>
		<category><![CDATA[Query]]></category>
		<category><![CDATA[query sql]]></category>
		<category><![CDATA[search menu]]></category>
		<category><![CDATA[sql queries]]></category>
		<category><![CDATA[WHERE]]></category>

		<guid isPermaLink="false">http://wizardinternetsolutions.com/?p=46</guid>
		<description><![CDATA[<p>A simple light weight &#038; efficient search menu that includes a count of the total items within each option. This can be customized for any needs.</p><p><a href="http://wizardinternetsolutions.com/web-database-design/ebay-style-search-menu-category-totals-count-displayed/">Ebay style search menu with category totals count displayed.</a>
<a href="http://wizardinternetsolutions.com">Website Design, Search Engine Optimization &amp; Internet Marketing - Wizard Internet Solutions</a></p>]]></description>
				<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div class="wp-caption alignright" style="width: 220px"><a href="http://www.crunchbase.com/company/ebay" target="_blank"><img class=" " style="border: 0pt none;" title="Image representing eBay as depicted in CrunchBase" src="http://www.crunchbase.com/assets/images/resized/0000/3625/3625v1-max-450x450.png" alt="Image representing eBay as depicted in CrunchBase" width="210" height="87" /></a><p class="wp-caption-text">Image via CrunchBase</p></div>
</div>
<p>I spent a few days lately working on a personal project and couldn&#8217;t get my search menu to function quite like i wanted. After several attempts with forms and such i wanted a less messy and more attractive search. After looking on <a class="zem_slink" title="eBay" rel="homepage" href="http://www.ebay.com" target="_blank">eBay</a> for something i realized that a similar search would work great for my needs and look good as well. Not only did it list all valid categories and options but it gave a total of the items listed for that category. After a few searches and a few attempts I got it working. Lets start by creating some demo data to work with, we will be using the below for this.</p>
<p style="text-align: left;"><a title="Ebay Style Menu Demo" href="http://wizardinternetsolutions.com/articles/examples/ebay-style-menu-demo/">Click here for a working demo</a></p>
<p>The files we will be working with can be downloaded at the bottom of the  page. The sql for this data is included.</p>
<table>
<tbody>
<tr style="text-align: right; font-weight: bold;">
<td style="text-align: right;" width="20">id</td>
<td style="text-align: center;" width="60">name</td>
<td style="text-align: center;" width="60">color</td>
<td style="text-align: center;" width="60">shape</td>
</tr>
<tr>
<td style="text-align: right;">1</td>
<td style="text-align: center;">Shape 1</td>
<td style="text-align: center;">red</td>
<td style="text-align: center;">square</td>
</tr>
<tr>
<td style="text-align: right;">2</td>
<td style="text-align: center;">Shape 2</td>
<td style="text-align: center;">blue</td>
<td style="text-align: center;">triangle</td>
</tr>
<tr>
<td style="text-align: right;">3</td>
<td style="text-align: center;">Shape 3</td>
<td style="text-align: center;">green</td>
<td style="text-align: center;">circle</td>
</tr>
<tr>
<td style="text-align: right;">4</td>
<td style="text-align: center;">Shape 4</td>
<td style="text-align: center;">red</td>
<td style="text-align: center;">triangle</td>
</tr>
<tr>
<td style="text-align: right;">5</td>
<td style="text-align: center;">Shape 5</td>
<td style="text-align: center;">blue</td>
<td style="text-align: center;">circle</td>
</tr>
</tbody>
</table>
<p>Now that we have some data to work with lets get started with the PHP that will create this search menu. Assuming you already have a MySQL connection made in you PHP document we will start by defining our 2 sql queries. The first query is used to get the count of all the items in each category (i.e. how many shapes are red, how many are blue, how many are green etc) and is done by using the Count and If statements to get our data.</p>
<p>The following will get a count of how many items are red and setting the results as reds:</p>
<pre class="brush:php">$sql = "SELECT Count(If((demo.color = 'red'),1,NULL)) AS reds FROM demo";
$query = mysql_fetch_array(mysql_query($sql));
echo "Red(".$query['reds'].")&lt;br/&gt;";</pre>
<p>The output of this should be &#8220;Red(2)&#8221;. We will later turn this into a link. Using this same Count statement we will form a much more advanced string for all of our options and later we will add a conditional WHERE clause to only get the results of options that we have already chosen. After adding the other option counts you should have something like this:</p>
<pre class="brush:php">$count_sql = "SELECT
 Count(If((demo.color = 'red'),1,NULL)) AS reds,
 Count(If((demo.color = 'blue'),1,NULL)) AS blues,
 Count(If((demo.color = 'green'),1,NULL)) AS greens,
 Count(If((demo.shape = 'square'),1,NULL)) AS squares,
 Count(If((demo.shape = 'triangle'),1,NULL)) AS triangles,
 Count(If((demo.shape = 'circle'),1,NULL)) AS circles
FROM demo";
$view_sql = "SELECT * FROM demo";</pre>
<p>As you can see the the first variable $count_sql uses our counts to get the amount of items in each category, when we add a WHERE statement it will only show the results that match our search conditions. The second $view_sql is used to select the items that match the search for viewing. On to the next section:</p>
<pre class="brush:php">if(isset($_GET['clear'])){
   $clear = $_GET['clear'];
   unset($_GET[$clear]);
}</pre>
<p>This will simply clear the variable for a specific option. This is used so that a user can remove a previously selected option from the results. The following code then checks for the existence of any chosen options and if they exist it then adds the appropriate WHERE condition to both of the sql variables. The $c variable is used to determine whether or not the AND statement is needed. The $link variable is used to set the full links for the options links below.</p>
<pre class="brush:php">if(isset($_GET['color']) || isset($_GET['shape'])){
   $c = FALSE;
   $count_sql .= " WHERE";
   $view_sql .= " WHERE";
   $link = '?';
   if(isset($_GET['color'])){
      if($c == FALSE){
         $count_sql .= " color='".$_GET['color']."'";
         $view_sql .= " color='".$_GET['color']."'";
         $link .= "color=".$_GET['color'];
         $c = TRUE;
      } else {
         $count_sql .= " AND color='".$_GET['color']."'";
         $view_sql .= " AND color='".$_GET['color']."'";
         $link .= "&amp;color=".$_GET['color'];
      }
   }
   if(isset($_GET['shape'])){
      if($c == FALSE){
         $count_sql .= " shape='".$_GET['shape']."'";
         $view_sql .= " shape='".$_GET['shape']."'";
         $link .= "shape=".$_GET['shape'];
         $c = TRUE;
      } else {
         $count_sql .= " AND shape='".$_GET['shape']."'";
         $view_sql .= " AND shape='".$_GET['shape']."'";
         $link .= "&amp;shape=".$_GET['shape'];
      }
   }
};</pre>
<p>Now that we have our sql statements complete the next section will build the search options.  I have used the php if statements shorthand version which follows the (condition ? if true : else) format. This is a great shortcut that can be used inline with echo and variable assignments. The link is then followed by the count for all items that match that option and meet the conditions of the WHERE statements. If the option has already been selected then a clear link becomes available in its place. This clear link will clear the set variable</p>
<pre class="brush:php">$result = mysql_query($count_sql);
$cnt_qry = mysql_fetch_array($result);
if(!isset($_GET['color'])){
   echo "Color&lt;br/&gt;";
   echo "&lt;a href='".((isset($link)) ? $link."&amp;" : "?")."color=red'&gt;Red&lt;/a&gt;(".$cnt_qry['reds'].")&lt;br/&gt;";
   echo "&lt;a href='".((isset($link)) ? $link."&amp;" : "?")."color=blue'&gt;Blue&lt;/a&gt;(".$cnt_qry['blues'].")&lt;br/&gt;";
   echo "&lt;a href='".((isset($link)) ? $link."&amp;" : "?")."color=green'&gt;Green&lt;/a&gt;(".$cnt_qry['greens'].")&lt;br/&gt;";
} else {
   echo "&lt;a href='".((isset($link)) ? $link."&amp;" : "?")."clear=color'&gt;Clear Color&lt;/a&gt;&lt;br/&gt;";
}
if(!isset($_GET['shape'])){
   echo "Shape&lt;br/&gt;";
   echo "&lt;a href='".((isset($link)) ? $link."&amp;" : "?")."shape=square'&gt;Square&lt;/a&gt;(".$cnt_qry['squares'].")&lt;br/&gt;";
   echo "&lt;a href='".((isset($link)) ? $link."&amp;" : "?")."shape=triangle'&gt;Triangle&lt;/a&gt;(".$cnt_qry['triangles'].")&lt;br/&gt;";
   echo "&lt;a href='".((isset($link)) ? $link."&amp;" : "?")."shape=circle'&gt;Circle&lt;/a&gt;(".$cnt_qry['circles'].")&lt;br/&gt;";
} else {
   echo "&lt;a href='".((isset($link)) ? $link."&amp;" : "?")."clear=shape'&gt;Clear Shape&lt;/a&gt;&lt;br/&gt;";
}</pre>
<p>Following the search menu output is the results of the search. This is a simple where loop on the results of the $view_sql query we built earlier. It loops through the results and outputs them to the browser.</p>
<pre class="brush:php">$result = mysql_query($view_sql);
while($view_qry = mysql_fetch_array($result)){
 echo $view_qry['id'].": ".$view_qry['name']." is ".$view_qry['shape']." and ".$view_qry['color'].".&lt;br/&gt;";
};</pre>
<p>This can be customized in many ways however you need with as many options as you need. You can style this menu to fit almost anywhere in your site. As long as the sql statements get run before the search bar code and the while loop those elements can be placed anywhere in the code to be run below. As always i hope this is enough to get you started and i hope i made it simple enough to understand. If you have any questions or comments please leave them below and i will answer them. If you feel you can improve on this please do by all means. If you send me your revisions i will add them here with all credit due.</p>
<p>Files for this demo:</p>
<ul>
<li><a title="Ebay Style Menu Demo" href="http://wizardinternetsolutions.com/articles/examples/ebay-style-menu-demo/">Click here for a working demo</a></li>
<li><a rel="attachment wp-att-259" href="http://wizardinternetsolutions.com/web-database-design/ebay-style-search-menu-category-totals-count-displayed/attachment/ebay-style-search-menu-demo/"></a><a href="http://wizardinternetsolutions.com/wp-content/uploads/2010/04/ebay-style-search-menu-demo.zip">Download Ebay Style Search Menu Files</a> (archive)<a href="http://wizardinternetsolutions.com/wp-content/uploads/2010/04/ebay-style-search-menu-demo.zip"><br />
</a></li>
</ul>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/pixy.gif?x-id=402c5d0c-1870-44e6-8862-bc4d98cda3da" alt="" /></div>
<h4>Incoming search terms:</h4><ul class="search-terms"><li>search menu php</li><li>sql find category count</li><li>ebay category selector jquery</li><li>ebay like menu</li><li>ebay style category selector</li><li>ebay style search</li><li>how to get ebay style search</li><li>ebay search sql statement</li><li>jquery category menu ebay style</li><li>jquery ebay style search</li><li>search categories design</li><li>how to make ebay like menu</li></ul><p><a href="http://wizardinternetsolutions.com/web-database-design/ebay-style-search-menu-category-totals-count-displayed/">Ebay style search menu with category totals count displayed.</a>
<a href="http://wizardinternetsolutions.com">Website Design, Search Engine Optimization &amp; Internet Marketing - Wizard Internet Solutions</a></p><img src="http://feeds.feedburner.com/~r/WizardInternetSolutions/~4/2cToF-25_os" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://wizardinternetsolutions.com/web-database-design/ebay-style-search-menu-category-totals-count-displayed/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://wizardinternetsolutions.com/web-database-design/ebay-style-search-menu-category-totals-count-displayed/</feedburner:origLink></item>
		<item>
		<title>Dynamic Multi-level CSS Menu with PHP and MySQL. SEO Ready.</title>
		<link>http://feedproxy.google.com/~r/WizardInternetSolutions/~3/ywkMynziDrw/</link>
		<comments>http://wizardinternetsolutions.com/web-database-design/dynamic-multilevel-css-menu-php-mysql/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 03:30:37 +0000</pubDate>
		<dc:creator>danieliser</dc:creator>
				<category><![CDATA[Web & Database Design]]></category>
		<category><![CDATA[auto increment]]></category>
		<category><![CDATA[count]]></category>
		<category><![CDATA[Deriv]]></category>
		<category><![CDATA[infinite levels]]></category>
		<category><![CDATA[link]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[parent menu]]></category>
		<category><![CDATA[Query]]></category>
		<category><![CDATA[search attempts]]></category>
		<category><![CDATA[sql create table]]></category>

		<guid isPermaLink="false">http://blog.wizardinternetsolutions.com/?p=37</guid>
		<description><![CDATA[<p>SEO Ready Dynamic CSS Menus. This is a simple PHP function that pulls a Multi-level menu from a MySQL table. You can easily adapt to any CSS style.</p><p><a href="http://wizardinternetsolutions.com/web-database-design/dynamic-multilevel-css-menu-php-mysql/">Dynamic Multi-level CSS Menu with PHP and MySQL. SEO Ready.</a>
<a href="http://wizardinternetsolutions.com">Website Design, Search Engine Optimization &amp; Internet Marketing - Wizard Internet Solutions</a></p>]]></description>
				<content:encoded><![CDATA[<address> </address>
<address> </address>
<address> </address>
<address>Since writing this post i have enhanced the script and now use V2 which you can check out here:<a title="Permanent Link to Single Query Dynamic  Multi-level Menu" rel="bookmark" href="../single-query-dynamic-multi-level-menu/"> Single Query Dynamic Multi-level Menu</a></address>
<address style="text-align: left;"> </address>
<p style="text-align: left;">I was recently working on a project for a client and couldn&#8217;t find a menu solution to fit my needs. I was looking to use a menu style similar to those found on <a title="CSS Play" href="http://www.cssplay.co.uk/menus/" target="_blank">Cssplay.co.uk</a>, but i wanted to build the menu on the fly from a MySQL database.  After many search attempts and several posts on php/mysql boards i realized i was going to have to work this out myself. I needed infinite levels and most tutorials only had options for 1 or 2 sub levels or weren&#8217;t completely dynamic and would require a table rebuild every time you add a new page.</p>
<h3>Creating The Menu</h3>
<p>My solution was a mix of several menus i found online. I decided to use a flat table and a simple recursive php function. The first step is working out the table structure. Here is a look at the table i used.</p>
<h4>The MySQL Table</h4>
<table style="width: 238px; height: 20px;">
<tbody>
<tr>
<td><strong>id</strong></td>
<td>label</td>
<td>link</td>
<td>parent</td>
<td>sort</td>
</tr>
</tbody>
</table>
<p>The <span style="text-decoration: underline;"><strong>id</strong></span> is you Primary Key field here, followed by <span style="text-decoration: underline;"><em>label</em></span> and <span style="text-decoration: underline;"><em>link</em></span> being the name and action of the option. The <span style="text-decoration: underline;"><em>parent</em></span> will be the <span style="text-decoration: underline;"><strong>id</strong></span> of the parent menu item and finally the <span style="text-decoration: underline;"><em>sort</em></span> field is used if you want any control over the order of your menu items.</p>
<p>Here is the sql</p>
<pre class="brush: sql">CREATE TABLE `menu` (
  `id` int(11) NOT NULL auto_increment,
  `label` varchar(50) NOT NULL default '',
  `link` varchar(100) NOT NULL default '#',
  `parent` int(11) NOT NULL default '0',
  `sort` int(11) default NULL,
  PRIMARY KEY  (`id`),
) ENGINE=MyISAM AUTO_INCREMENT=248 DEFAULT CHARSET=latin1;</pre>
<p>Now that we have a table to take information from we need some data</p>
<table border="0">
<tbody>
<tr>
<td><strong>id</strong></td>
<td>label</td>
<td>link</td>
<td>parent</td>
<td>sort</td>
</tr>
<tr>
<td>1</td>
<td>Home</td>
<td>#home</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
</tr>
<tr>
<td>2</td>
<td>Code</td>
<td>#code</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
</tr>
<tr>
<td>3</td>
<td>Contact</td>
<td>#contact</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
</tr>
<tr>
<td>4</td>
<td>PHP</td>
<td>#php</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">0</td>
</tr>
<tr>
<td>5</td>
<td>CSS</td>
<td>#css</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">0</td>
</tr>
<tr>
<td>6</td>
<td>Scripts</td>
<td>#scripts</td>
<td style="text-align: right;">4</td>
<td style="text-align: right;">0</td>
</tr>
<tr>
<td>7</td>
<td>Help</td>
<td>#help</td>
<td style="text-align: right;">4</td>
<td style="text-align: right;">0</td>
</tr>
<tr>
<td>8</td>
<td>Archive</td>
<td>#archive</td>
<td style="text-align: right;">6</td>
<td style="text-align: right;">0</td>
</tr>
<tr>
<td>9</td>
<td>Snippet</td>
<td>#snippet</td>
<td style="text-align: right;">8</td>
<td style="text-align: right;">0</td>
</tr>
</tbody>
</table>
<p>The links can be in any form as you will build them later. eg. ?p=84, http://url, #anchor.</p>
<h4>The PHP Function</h4>
<p>Now lets take a look at the php. This is a simplified version</p>
<pre class="brush: php">function display_children($parent, $level) {
    $result = mysql_query("SELECT a.id, a.label, a.link, Deriv1.Count FROM `menu` a  LEFT OUTER JOIN (SELECT parent, COUNT(*) AS Count FROM `menu` GROUP BY parent) Deriv1 ON a.id = Deriv1.parent WHERE a.parent=" . $parent);
    echo "&lt;ul&gt;";
    while ($row = mysql_fetch_assoc($result)) {
        if ($row['Count'] &gt; 0) {
            echo "&lt;li&gt;&lt;a &#104;ref='" . $row['link'] . "'&gt;" . $row['label'] . "&lt;/a&gt;";
			display_children($row['id'], $level + 1);
			echo "&lt;/li&gt;";
        } elseif ($row['Count']==0) {
            echo "&lt;li&gt;&lt;a &#104;ref='" . $row['link'] . "'&gt;" . $row['label'] . "&lt;/a&gt;&lt;/li&gt;";
        } else;
    }
    echo "&lt;/ul&gt;";
}</pre>
<p>So lets start with the query.</p>
<pre class="brush: php">$result = mysql_query("SELECT a.id, a.label, a.link, Deriv1.Count FROM `menu` a  LEFT OUTER JOIN (SELECT parent, COUNT(*) AS Count FROM `menu` GROUP BY parent) Deriv1 ON a.id = Deriv1.parent WHERE a.parent=" . $parent);</pre>
<p>It looks complicated but all it is doing is getting the information for each menu item for a parent and a count of how many children it has. The results would look like this:</p>
<table border="0">
<tbody>
<tr>
<td><strong>id</strong></td>
<td>label</td>
<td>link</td>
<td>count</td>
</tr>
<tr>
<td style="text-align: right;">1</td>
<td>Home</td>
<td>#home</td>
<td style="text-align: right;">0</td>
</tr>
<tr>
<td style="text-align: right;">2</td>
<td>Code</td>
<td>#code</td>
<td style="text-align: right;">2</td>
</tr>
<tr>
<td style="text-align: right;">3</td>
<td>Contact</td>
<td>#contact</td>
<td style="text-align: right;">0</td>
</tr>
</tbody>
</table>
<p>These results are the contents of the top layer or main menu, just after the sql query comes a simple <em><strong>echo</strong></em> to create our opening &lt;ul&gt; tags. Followed by the brains of the function inside this while statement:</p>
<pre class="brush: php">while ($row = mysql_fetch_assoc($result)) {
	if ($row['Count'] &gt; 0) {
		echo "&lt;li&gt;&lt;a &#104;ref='" . $row['link'] . "'&gt;" . $row['label'] . "&lt;/a&gt;";
		display_children($row['id'], $level + 1);
		echo "&lt;/li&gt;";
	} elseif ($row['Count']==0) {
		echo "&lt;li&gt;&lt;a &#104;ref='" . $row['link'] . "'&gt;" . $row['label'] . "&lt;/a&gt;&lt;/li&gt;";
	} else;
}</pre>
<p>This statement simply outputs the appropriate &lt;li&gt; tags and links for each item on the menu and then checks to see if that item has any children. If the count is more than zero then it calls the entire function over to build the child menu. Then a simple closing &lt;/ul&gt; tag to finish it off.<br />
To call the menu simply run the function with the level you want to display for example:</p>
<pre class="brush: php">display_children(0, 1);</pre>
<p>Would return:</p>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#code">Code</a>
<ul>
<li><a href="#php">PHP</a>
<ul>
<li><a href="#scripts">Scripts</a>
<ul>
<li><a href="#archive">Archive</a>
<ul>
<li><a href="#snippet">Snippet</a></li>
</ul>
</li>
<li><a href="#help">Help</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#css">CSS</a></li>
</ul>
</li>
<li><a href="#contact">Contact</a></li>
</ul>
<pre class="brush: php">display_children(4, 1);</pre>
<p>Would return only the children of PHP or (<strong>id #</strong>4)</p>
<ul>
<li><a href="#scripts">Scripts</a>
<ul>
<li><a href="#archive">Archive</a>
<ul>
<li><a href="#snippet">Snippet</a></li>
</ul>
</li>
<li><a href="#help">Help</a></li>
</ul>
</li>
</ul>
<p>This second use can come in handy if you want to build a sub menu any where in your site.</p>
<p>The menu can be further customized  as i mentioned above with css as can be seen in use at <a title="B&amp;B Wholesale Metals" href="http://www.bbmetals.net" target="_blank">B&amp;B Metals</a>.</p>
<p>The code for the menu on that site is slightly more complex due to different css classes being used for lower levels in the menu. You can easily sort the menu by adding a sort statement to the sql statement and giving your menu items a sort order.</p>
<h3>Styling The Menu</h3>
<p>Now after all that it doesnt look like much yet. But im gonna show you how to make this into a horizontal dropdown menu although you could use this to make any sort of menu type.</p>
<h4>Modifying the PHP</h4>
<p>The first thing we have to do now is add add a class to the output of the php script.</p>
<p>Start by replacing:</p>
<pre class="brush: php">echo "&lt;li&gt;&lt;a &#104;ref='" . $row['link'] . "'&gt;" . $row['label'] . "&lt;/a&gt;&lt;/li&gt;";</pre>
<p>With:</p>
<pre class="brush: php">echo "&lt;li class='list'&gt;&lt;a class='list_link' &#104;ref='" . $row['link'] . "'&gt;" . $row['label'] . "&lt;/a&gt;&lt;/li&gt;";</pre>
<p>If you want a different style for your lower levels then you will want to use the code below instead of the one above.</p>
<pre class="brush: php">echo "&lt;li class='level".$level."'&gt;&lt;a class='level".$level."' &#104;ref='" . $row['link'] . "'&gt;" . $row['label'] . "&lt;/a&gt;&lt;/li&gt;";</pre>
<p>Now that our links have been assigned a class we can style them any way we choose. If you want to style layer 2 differently then simply use the .layer2 class to change that. Now that you have your menu in the right format ie. Unordered and Ordered lists you can use just about any css menu around. I recommend checking out the ones over at <a title="CSS Play" href="http://www.cssplay.co.uk/menus/" target="_blank">Cssplay.co.uk</a>, of course if you like there stuff make sure you donate.  Another way that you can code your css menus is to give your menu a class, lets say .menu, apply that class to your top container and assign the levels of the menu as</p>
<pre class="brush: css">.menu ul{color:#FFF;} /* Main container, includes the background of the static portion of the menu */
.menu ul li{color:#FFF;} /* This is the style for the main menu items */
.menu ul ul{color:#FFF;} /* This is the container for the first submenu */
.menu ul ul li{color:#FFF;} /* This is the style for the submenus */</pre>
<p>And so on and so on. You can style the links themselves as well by using the .menu a{}. This will alter all links in the menu. To define a different style for a lower level in the menu you would simply change it to .menu ul ul a{} for the second level.</p>
<p>I wont go over all the styling as we would be here forever so if you have any questions feel free to ask and ill be glad to help.</p>
<p>Since writing this post i have enhanced the script and now use V2 which  you can check out here:<a title="Permanent Link to Single Query Dynamic   Multi-level Menu" rel="bookmark" href="../single-query-dynamic-multi-level-menu/"> Single Query  Dynamic Multi-level Menu</a></p>
<h4>Incoming search terms:</h4><ul class="search-terms"><li>php dynamic menu</li><li>dynamic menu in php</li><li>dynamic menu php</li><li>dynamic menu php mysql</li><li>php multi level menu</li><li>menu php mysql</li><li>php mysql menu</li><li>php dynamic menu from database</li><li>menu in php</li><li>php mysql dynamic menu</li><li>recursive menu php mysql</li><li>php menu mysql</li></ul><p><a href="http://wizardinternetsolutions.com/web-database-design/dynamic-multilevel-css-menu-php-mysql/">Dynamic Multi-level CSS Menu with PHP and MySQL. SEO Ready.</a>
<a href="http://wizardinternetsolutions.com">Website Design, Search Engine Optimization &amp; Internet Marketing - Wizard Internet Solutions</a></p><img src="http://feeds.feedburner.com/~r/WizardInternetSolutions/~4/ywkMynziDrw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://wizardinternetsolutions.com/web-database-design/dynamic-multilevel-css-menu-php-mysql/feed/</wfw:commentRss>
		<slash:comments>46</slash:comments>
		<feedburner:origLink>http://wizardinternetsolutions.com/web-database-design/dynamic-multilevel-css-menu-php-mysql/</feedburner:origLink></item>
	</channel>
</rss>
