我已经为 magento 创建了自定义模块,表格中的问题由类别和子类别组成,现在我想显示以下内容
Category 1
Subcategory 1
Subcategory 2
Subcategory 3
Category 2
Subcategory 1
Subcategory 2
Subcategory 3
Category 3
Subcategory 1
Subcategory 2
Subcategory 3
我的代码是
$collection = Mage::getModel('supportportal/supportportal')->getCollection();
// -> addFieldToFilter('parent_category_id', array('neq' => 0));
foreach ($collection as $data) {
$collection2 = Mage::getModel('supportportal/supportportal')->getCollection()
-> addFieldToFilter('category_id', array('eq' => $data->getData('parent_category_id')));
foreach ($collection2 as $data2) {
echo '<h4>'.$data2->getData('category_name').'</h4>';//display category having no parent
echo '<ul>';
echo '<li>
<a href="'.$data->getData('category_Url').'">'.$data->getData('category_name').'</a></li>';
//display category having parent
echo '</ul>';
}
}
我们的表结构是
fmequestion_category
CREATE TABLE `fmequestion_category` (
`category_id` int(10) NOT NULL AUTO_INCREMENT,
`category_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`category_description` text NOT NULL,
`category_Url` varchar(255) NOT NULL,
`parent_category_id` int(11) DEFAULT NULL,
`store_id` varchar(250) DEFAULT NULL,
`meta_title` text,
`meta_keywords` text,
`meta_description` text,
`creation_date` datetime DEFAULT NULL,
`last_updated_date` datetime DEFAULT NULL,
`status` smallint(6) DEFAULT NULL,
PRIMARY KEY (`category_id`),
KEY `FK_Question_category_parent_category` (`parent_category_id`)
) ENGINE=InnoDB AUTO_INCREMENT=81 DEFAULT CHARSET=utf8
我如何像上面那样显示