你好
這是我的代碼....問題是在$product
變量。
有什麼辦法解決這個問題嗎?
它被定義兩次,導致問題覆蓋PHP變量範圍困惑
修訂
$productsIDs = array();
foreach ($rowsProducts as &$product) {
$product["features"] = &$productsFeatures[$product["product_id"]];
$productsIDs[] = $product["product_id"];
}
//GET STOCK FEATURES
$sqlIds=implode(",",$productsIDs);
$sql="SELECT * FROM eshop_products_stock WHERE product_id IN ($sqlIds)";
$productsStock = $db->getRecordSet($sql);
$sql="SELECT * FROM `eshop_features_valuestr` WHERE feature_id IN ".
"(SELECT DISTINCT feature1_id FROM eshop_products_stock WHERE product_id IN ($sqlIds))" .
" AND language_code='$lang'";
$productsSizes = $db->getRecordSet($sql);
$sql="SELECT * FROM `eshop_features_valuestr` WHERE feature_id IN ".
"(SELECT DISTINCT feature2_id FROM eshop_products_stock WHERE product_id IN ($sqlIds))".
" AND language_code='$lang'";;
$productsColors = $db->getRecordSet($sql);
$productsSizesV=array();
foreach($productsSizes as $size)
{
$productsSizesV[$size["value"]]=$size["title"];
}
$productsColorsV=array();
foreach($productsColors as $color)
{
$productsColorsV[$color["value"]]=$color["title"];
}
//Group by product stock
$productsStockV=array();
$product="";
foreach($productsStock as $product)
{
$productsStockV[$product["product_id"]]["sizes"][]=$product["feature1_value"];
$productsStockV[$product["product_id"]]["colors"][]=$product["feature2_value"];
}
這是什麼問題? – Gumbo 2010-11-14 18:36:13
沒有必要在'foreach'循環之前聲明'$ product';你應該刪除'$ product =「」'這行,因爲它只是混淆了事情。 – meagar 2010-11-14 18:37:42