Sunday, January 24, 2010

Unlimited Categories Implementation by Recursively

  1. 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;
  2. 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;
    }
  3. 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;
    }
  4. Usage
    $categories = category::get_all(0,0,2); // All Type, Parent Id = 0, MaxDepth = 2
    echo category::output_options($categories, 2);

Saturday, January 23, 2010

Firefox Extensions of Mine

Generated: Sat Jan 23 2010 22:31:39 GMT+0800 (China Standard Time)
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]
Disabled Extensions: [18]
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

  1. Press and hold Fn+Shift, then input 15324 (The number lock led will turning)
  2. Press Fn+r, it will show up the temporary of modules.
p.s. This is works on my inspiron 1420.