- MySQL Table Definition:
CREATE TABLE `categories` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(50) NOT NULL,
`parent_id` int(10) unsigned zerofill NOT NULL,
`type` int(10) unsigned zerofill NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8; - Implementation for DataObject
public static function get_all($type = NULL, $parent_id = 0, $depth = 3, $count = 0){
if($count == $depth) return;
$condition = is_int($type) ? "AND type=$type" : '';
$categories = Database::instance()->query("SELECT * FROM categories WHERE parent_id = '$parent_id' $condition")->result_array(FALSE);
if(count($categories) == 0) return NULL;
foreach ($categories as &$category) {
$category['parent_id'] = intval($category['parent_id']);
$category['type'] = intval($category['type']);
$subcategories = self::get_all($type, $category['id'], $depth, $count+1);
if($subcategories) $category['subcategories'] = $subcategories;
}
return $categories;
} - Implementation for Logical UI
public static function output_options($categories, $depth = 2, $level = 0, $nest = 0){
if($nest == $depth || !is_array($categories)) return '';
$html = '';
foreach($categories as $category){
$html .= "<option value=\"{$category['id']}\"";
if($nest < $level) $html .= ' disabled="disabled"';
$html .= '>';
for($i=0,$j=$nest;$i<$j;$i++) $html .= ' ';
$html .= "{$category['name']}</option>\n";
if(isset($category['subcategories'])) {
$html .= self::output_options($category['subcategories'], $depth, $level, $nest+1);
}
}
return $html;
} - Usage
$categories = category::get_all(0,0,2); // All Type, Parent Id = 0, MaxDepth = 2
echo category::output_options($categories, 2);
Sunday, January 24, 2010
Unlimited Categories Implementation by Recursively
Saturday, January 23, 2010
Firefox Extensions of Mine
User Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)
Build ID: 20100115144158
Enabled Extensions: [23]
- AutoProxy 0.3b4.0+.2009110800
- Cache Status 0.7.9
- Capture Fox 0.7.0
- ColorZilla 2.0.2
- Delicious Bookmarks 2.1.072
- Domain Details 2.6
- Echofon 1.9.4.1
- Firebug 1.5.0
- Firecookie 1.0.2
- Firefox Showcase 0.9.5.5
- FireGestures 1.5.5.1
- FoxyProxy Standard 2.18
- Greasefire 1.0.4
- Greasemonkey 0.8.20091209.4
- Microsoft .NET Framework Assistant 1.1
- MR Tech Toolkit 6.0.4
- Organize Status Bar 0.6.4
- Read It Later 2.0.3
- RefControl 0.8.13
- SearchStatus 1.33
- Tab Mix Plus 0.3.8.2
- Tamper Data 10.1.0
- Xmarks 3.4.5
Disabled Extensions: [18]
- Adblock Plus 1.1.3
- aliedit 1.1.0.3
- CookieSwap 0.5.248Beta
- CS Lite 1.4
- FireGPG 0.7.10
- FireQuery 0.3
- FireShot 0.80
- Flagfox 3.3.20
- IE Tab 1.5.20090525
- JavaScript Deobfuscator 1.5.5
- Live HTTP headers 0.15
- MeasureIt 0.3.9
- NoRedirect 1.2.4
- Page Speed 1.4
- Pixel Perfect 1.1.0
- Server Spy 0.1.6
- Total Validator 6.1.1
- User Agent Switcher 0.7.2
Total Extensions: 41
Installed Themes: [1]
Installed Plugins: (6)
- Adobe Acrobat
- Mozilla Default Plug-in
- Shockwave Flash
- Silverlight Plug-In
- Thunder DapCtrl Plugin
- WPI Detector 1.1
Best Fonts for Web Design
Arial
- 12px – 16px (text, tips, title)
- 12px+, Smooth (text, title)
BitStream vera Sans
Calibri
- 14px+, Smooth (text, title)
Comic Sans MS
- 12px+, Smooth (text, title)
Consolas (Monospaced)
- 12px+, Smooth (text)
Courier / Courier New (Monospaced)
- 11px+ (text, tips, title, code)
- 12px+, Smooth (text, title)
Ebrima
- 14px+, Smooth
Georgia
- 14px+
- 14px+, Smooth
Helvetica Neue / Helvetica
Lucida Grande / Lucida Sans Unicode / Lucida Sans
Luxi Sans
Monaco (Monospaced)
Segoe UI
- 14px+, Smooth
Tahoma
- 11px+ (text, tips)
- 12px+, Smooth (text, title)
Simple Arabic / Simple Arabic Fixed (Monospaced)
- 12px+
- 14px+, Smooth
Verdana
- 11px+
- 12px+, Smooth
Last updated @ 2010.1.23
Sunday, January 17, 2010
A simple implementation for alternate output in PHP
This function was original from Kohana’s Text Helper.
/**
* Alternates between two or more strings.
*
* @param string strings to alternate between
* @return string
*/
public static function alternate()
{
static $i;
if (func_num_args() === 0)
{
$i = 0;
return '';
}
$args = func_get_args();
return $args[($i++ % count($args))];
}
Saturday, January 2, 2010
Engineering mode in DELL Laptop
- Press and hold Fn+Shift, then input 15324 (The number lock led will turning)
- Press Fn+r, it will show up the temporary of modules.
Monday, December 21, 2009
Contact
Email: billy [at] dreammx.com
MSN: billychow [at] live.com
Gtalk: billychou [at] gmail.com
Google Voice: (209) 677-7783
Skype: billychow.dreammx
Google Wave: billychou [at] googlewave.com
If you have PGP/GnuPG, you can use my public key for email.
K.I.S.S
KISS 原则不仅仅适用于计算机领域,也同样适用于任何其它的事物。尤其是对一些比较偏执的人或事物,他(它)们不断追求完美,却不断被完美本身所打败。当这一切接近极限,并超过极限时,便会回归原点,重新开始,往往复复。
也许,你是时候该稍微停下来思考一下了。如果前路已不再长,你还会继续前行吗?或是调个头,选择一条更短,但是更好的路来走?
这是个问题。
Sunday, December 20, 2009
使用 Windows Live Writer + Tor + Provixy 发布 Blogger
之前便有通过 Tor + WLW 更新 Blogger 的想法,但是因为一个 HTTP Header 的问题,一直没有成功,也没有去寻找原因。今天突然心血来潮想起这事,便网上搜索一番,果然是有解决方案的……也真的是佩服自己,有些事情本来一下就可以解决的,却总是为了省那么一点儿力却浪费大把的时间啊!
相关方法请自行 Google 之。
