Webmaster Sucks Here I share stuff I used to suck at as a novice webmaster..

7Jan/11Off

Recursive Category Listing

Webmasters allways use category trees, i wrote a function about creating category trees with using recursive function.

<?php
header('Content-Type: text/html; charset=UTF-8');

include($_SERVER['DOCUMENT_ROOT']."/mysql.inc.php");

function categories($firstCategory,$node)
{
	$kQ = mysql_query("SELECT * FROM categories WHERE category= ".$firstCategory);
	if(mysql_num_rows($kQ) > 0)
	{
		echo(str_repeat("\t",$node+1)."<ul>\n");
		$node++;
		while($k = mysql_fetch_array($kQ))
		{
			//str_repeat is for "view source" format, we set TAB character for readable HTML
			echo(str_repeat("\t",$node)."<li>".($node+1)." ".$k["name"]."</li>\n");

			// Recursive, call function it self
			categories($k["id"], $node);
		}
		echo(str_repeat("\t",$node)."</ul>\n");
	}
}
categories(0,-1);
?>

Output :

  • Food
    • Fruits
      • Apple
      • Banana
    • Vegetables
      • Tomatoes
      • Aborgin
  • Drinks
    • Soft
      • Fruit Juice
        • Apple Juice
        • Strawberry Juice
      • Milk
Tagged as: categories php, category list, recursive function, recursive functions php, recursive php, str_repeat, str_repeate php, WordPress 2 Comments
   

Webmaster Sucks

  • Email Subscription

Social

spacer

spacer
spacer

Categories

  • Design
  • General
  • Google
  • Html & Javascript
  • Linux
  • MySQL
  • Php
  • Security
  • SEO
  • Social Networks
  • Windows
  • WordPress

Recent comments

  • WebmasterSucks on Signing a Windows Programs
  • noname on Recursive Category Listing
  • ithobari on Change Time Zone with htaccess
  • singapore web design on Optimize PHP Codes Tricks
  • how to stop snorings on HTML5 Canvas Cheat Sheet v1.0

Tags

blogger chura clean br virus date calculation download download avast download avast free download avast free edition Google google analytics google badware google blocks google sitemap google twitter htaccess html5 html 5 br exploit br virus br virus removal internet explorer javascript jk.chura.pl jl.chura.pl remove jl.chura.pl virus Linux md5 msn MySQL password Php php 5.2.9 remove br virus replace search engine optimization SEO ssh trojan br twitter twitting virus virus exploit br virus html br WordPress yahoo

Calendar

February 2015
M T W T F S S
« Oct    
 1
2345678
9101112131415
16171819202122
232425262728  

Archives

  • October 2013
  • June 2011
  • January 2011
  • December 2010
  • October 2010
  • May 2010
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009

@ Webmaster Sucks

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.