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(...)';) –