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
- Fruits
- Drinks
- Soft
- Fruit Juice
- Apple Juice
- Strawberry Juice
- Milk
- Fruit Juice
- Soft
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
Categories
- Design
- General
- 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
M | T | W | T | F | S | S |
---|---|---|---|---|---|---|
« Oct | ||||||
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
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