如何为列" product_in_stock"排序子项的数组。 Virtuemart 3

时间:2017-02-23 09:20:28

标签: mysql arrays sorting

我在父级中有一系列子项。以下是形成它的代码。您需要通过product_in_stock添加或更改排序数组? (库存中的第一个儿童用品)

谢谢!

function getProductChilds ($product_id) {
    if (empty($product_id)) {
        return array();
    }
    $db = JFactory::getDBO ();
    $db->setQuery (
       'SELECT * FROM `#__virtuemart_products` p
        LEFT JOIN `#__virtuemart_products_'.VMLANG.'` pl USING (`virtuemart_product_id`)
        LEFT JOIN `#__virtuemart_product_medias` pm USING (`virtuemart_product_id`)
        LEFT JOIN `#__virtuemart_medias` med USING (`virtuemart_media_id`)
        LEFT JOIN `#__virtuemart_product_prices` pp USING (`virtuemart_product_id`)
        WHERE `p`.`product_parent_id` = '. (int)$product_id . '
        GROUP BY `pm`.`virtuemart_product_id`'
    );
    return $db->loadObjectList ();
}

1 个答案:

答案 0 :(得分:0)

商定

function getProductChilds ($product_id) {
if (empty($product_id)) {
return array();
}
$db = JFactory::getDBO ();
$db->setQuery ('SELECT * FROM `#__virtuemart_products` p
LEFT JOIN `#__virtuemart_products_'.VMLANG.'` pl USING (`virtuemart_product_id`)
LEFT JOIN `#__virtuemart_product_medias` pm USING (`virtuemart_product_id`)
LEFT JOIN `#__virtuemart_medias` med USING (`virtuemart_media_id`)
LEFT JOIN `#__virtuemart_product_prices` pp USING (`virtuemart_product_id`)
WHERE `p`.`product_parent_id` = '. (int)$product_id . '
GROUP BY `pm`.`virtuemart_product_id` ORDER BY p.`product_in_stock` DESC, `virtuemart_product_id` ASC');
return $db->loadObjectList ();
}

function getProductChilds ($product_id) {
if (empty($product_id)) {
return array();
}
$db = JFactory::getDBO ();
$db->setQuery ('SELECT * FROM `#__virtuemart_products` p
LEFT JOIN `#__virtuemart_products_'.VMLANG.'` pl USING (`virtuemart_product_id`)
LEFT JOIN `#__virtuemart_product_medias` pm USING (`virtuemart_product_id`)
LEFT JOIN `#__virtuemart_medias` med USING (`virtuemart_media_id`)
LEFT JOIN `#__virtuemart_product_prices` pp USING (`virtuemart_product_id`)
WHERE `p`.`product_parent_id` = '. (int)$product_id . '
GROUP BY `pm`.`virtuemart_product_id` ORDER BY product_in_stock DESC');
return $db->loadObjectList ();
}