1
需要的ID我是相当新的Zend框架,并搜查了几天没有找到一个例子了以下问题:Zend_Db的嵌套查询,其中一个查询从另一个
结果我试图从代码实现下面是一个列表,它将在主类别中包含匹配的子类别,并遍历我的所有主类别。
实施例:
设备(主类别)
- 微波
- 火炉
电子(主类别)
- 计算机
- 无线电
这是代码(我再也不知道该怎么做;我的思维过程是不嵌套foreach()
,与第二foreach()
获得的主要类别ID从第一选择):
// Get Categories with Sub Categories
$catid = 0;
$selectmain = $this->dbhInstance->select()
->from(array('a' => 'code_sub_category'),
array('b.id as mainid', 'b.site_category'))
->join(array('b' => 'site_categories'),
'b.id = a.site_category_id')
->group("b.id")
->order("b.site_category");
$selectsub = $this->dbhInstance->select()
->from(array('a' => 'code_sub_category'),
array('a.id as subid', 'a.sub_category', 'a.site_category_id'))
->join(array('b' => 'site_categories'),
'b.id = a.site_category_id')
->where("a.site_category_id = '" . $catid . "'")
->order("a.sub_category");
$fetch = $this->dbhInstance->fetchAll($selectmain);
$fetch2 = $this->dbhInstance->fetchAll($selectsub);
//var_dump($fetch2);
$items = array();
$items2 = array();
foreach ($fetch as $key => $value) {
$catid = $value['id'];
$items = array_merge($items, array($key => $value));
foreach ($fetch2 as $key => $value) {
$items = array_merge($items, array($key => $value));
}
$this->view->getsubcategories = $items;
}
$this->view->getmaincategories = $items;
//End FULL Categories for My Categories
获取此错误 带有消息'SQLSTATE [HY000]:一般错误:1221异常'PDOException'在/var/www/html/library/Zend/Db/Statement/Pdo.php中错误地使用了UNION和ORDER BY' :228 Stack trace:#0 /var/www/html/library/Zend/Db/Statement/Pdo.php(228): – user1735078
尝试从两个查询中删除' - > order(...)';) –