cat_term - holds the basic information about single terms.
CREATE TABLE `cat_term` (
`term_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(200) NOT NULL DEFAULT '',
`slug` varchar(200) NOT NULL DEFAULT '',
`term_group` varchar(250) NOT NULL DEFAULT '0',
PRIMARY KEY (`term_id`),
UNIQUE KEY `slug` (`slug`),
KEY `name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8
cat_term_taxonomy - defines the taxonomy - either tag, category, or custom taxonomy
CREATE TABLE `cat_term_taxonomy` (
`term_taxonomy_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`term_id` bigint(20) unsigned NOT NULL DEFAULT '0',
`taxonomy` varchar(32) NOT NULL DEFAULT '',
`description` longtext NOT NULL,
`parent` bigint(20) unsigned NOT NULL DEFAULT '0',
`count` bigint(20) NOT NULL DEFAULT '0',
PRIMARY KEY (`term_taxonomy_id`),
UNIQUE KEY `term_id_taxonomy` (`term_id`,`taxonomy`),
KEY `taxonomy` (`taxonomy`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8
Here is the function:
function build_tree_drop($parent_id = 0, $level = 0) {
$getJoin = mysql_query("SELECT * FROM cat_term_taxonomy INNER JOIN cat_term ON cat_term_taxonomy.term_id=cat_term.term_id WHERE parent='" . $parent_id . "'");
$getcate = '';
foreach ($getJoin as $row) {
//indent as necessary and print name
$getcate .= '<option value="' . $row->term_id . '" class="level-' . $row->parent . '">';
$getcate .= str_repeat(' ', $level) . $row->name . "\n";
$getcate .= '</option>';
//we want to see all the children that belong to this
//node… so we need to call *this* function again
$getcate .= $this->build_tree_drop($row->term_id, $level + 1);
}
return $getcate;
}
echo $this->Model->build_tree_drop($parent_id = 0, $level = 0);
Result:cat_term - holds the basic information about single terms.
CREATE TABLE `cat_term` (
`term_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(200) NOT NULL DEFAULT '',
`slug` varchar(200) NOT NULL DEFAULT '',
`term_group` varchar(250) NOT NULL DEFAULT '0',
PRIMARY KEY (`term_id`),
UNIQUE KEY `slug` (`slug`),
KEY `name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8
cat_term_taxonomy - defines the taxonomy - either tag, category, or custom taxonomy
CREATE TABLE `cat_term_taxonomy` (
`term_taxonomy_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`term_id` bigint(20) unsigned NOT NULL DEFAULT '0',
`taxonomy` varchar(32) NOT NULL DEFAULT '',
`description` longtext NOT NULL,
`parent` bigint(20) unsigned NOT NULL DEFAULT '0',
`count` bigint(20) NOT NULL DEFAULT '0',
PRIMARY KEY (`term_taxonomy_id`),
UNIQUE KEY `term_id_taxonomy` (`term_id`,`taxonomy`),
KEY `taxonomy` (`taxonomy`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8
Here is the function:
function build_tree_drop($parent_id = 0, $level = 0) {
$getJoin = mysql_query("SELECT * FROM cat_term_taxonomy INNER JOIN cat_term ON cat_term_taxonomy.term_id=cat_term.term_id WHERE parent='" . $parent_id . "'");
$getcate = '';
foreach ($getJoin as $row) {
//indent as necessary and print name
$getcate .= '<option value="' . $row->term_id . '" class="level-' . $row->parent . '">';
$getcate .= str_repeat(' ', $level) . $row->name . "\n";
$getcate .= '</option>';
//we want to see all the children that belong to this
//node… so we need to call *this* function again
$getcate .= $this->build_tree_drop($row->term_id, $level + 1);
}
return $getcate;
}
echo $this->Model->build_tree_drop($parent_id = 0, $level = 0);
Result:[--Menu--] Codeigniter H - How to MySQL PHP
0 comments:
Post a Comment