1

首先,我知道目前这是不正确的。我知道这一点,因为它不起作用。话虽如此,任何有助于让我更接近我想要的结果的帮助都将受到赞赏。

我有一个查询:

$query = "SELECT cat.*, 
       prod.title                            AS product, 
       cat1.title                            AS category, 
       (SELECT cat2.* 
        FROM   ic_store_catalog AS cat2 
        WHERE  cat2.parentid = cat.parentid) AS children 
FROM   ic_store_catalog AS cat 
       LEFT JOIN ic_products AS prod 
              ON cat.productid = prod.productid 
       LEFT JOIN ic_product_categories AS cat1 
              ON cat.categoryid = cat1.categoryid 
WHERE  `storeid` = $storeid 
       AND `column` = $column 
       AND `parentid` = 0 
ORDER  BY `the_order` ASC";

这个错误给了我:Operand should contain 1 column(s)作为问题。这存在于子选择中保证。

print_r现在,当我使用in时,我需要实现PHPArray结构与此类似:

[0] => Array
            (
                [catalogID] => 165
                [storeID] => 0
                [categoryID] => 7
                [parentID] => 0
                [productID] => 4
                [title] => 
                [column] => 1
                [the_order] => 1
                [cat_order] => 1
                [category] => Cookies & Brownies
                [children] => Array 
                (
                  [0] => Array (
                      [catalogID] => 166
                      [storeID] => 0
                      [categoryID] => 8
                      [parentID] => 7
                      [productID] => 5
                      [the_order] => 1
                      [cat_order] => 1
                      [category] => Brownies
                  )
                )
            )

任何有助于让我更接近这个结果的帮助表示赞赏。

4

1 回答 1

0

(SELECT cat2.* FROM ic_store_catalog AS cat2 WHERE cat2.parentid = cat.parentid)

您应该只替换cat2.*一列代表children.

于 2013-01-15T20:30:06.857 回答