2012-03-10 11 views
1

私はサイトに挿入された場所の製品メニューを作成しています。障害が発生しただけで、私はそれを修正する方法を見つけることができません。PHPとMYSQLを使った動的な動的製品メニュー

マイコード:

public function getProductList($type = NULL, $brand = NULL){ 
    if(empty($type) and empty($brand)){ 

    $types = $this->productmodel->getTypeList(); // Category as arraylist 
    $brands = $this->productmodel->getBrandList(); // Brandnames as arraylist 
    $products = $this->productmodel->getProduct(); // All available products 

    $menu = array(); 

    foreach($products as $product) { 
      [$product['brand_id']] 
      $menu[$product['type_id']] = array (
     'type' => array(
     'url' => base_url('index.php/productcontroller/getProductList/'.$product['type_id']), 
     'type_name' => $types[$product['type_id']] 
     ) 
    ); 

     // Brands 
     $menu[$product['type_id']]['brands'] = array (
     $product['brand_id']['brand'] => array(
     'url' => base_url('index.php/productcontroller/getProductList/'.$product['type_id'].'/'.$product['brand_id']), 
     'brand_name' => $brands[$product['brand_id']] 
     ) 
    ); 
} 
return $menu; 
} 

Futherは、次のように説明し

私は、データベース内の3つのテーブルを持っています。 1.Type:with:type.idとtype_name、 2.Brand:with:brand.idとbrand_type、 3.Products - with:上記のテーブルのIDを持つ製品に関するすべての情報。

最新の製品のみが表示されます。だから他のすべてのブランド名は上書きされます。私は重複しているブランド名を上書きしたかったので、そのブランド名( 'id']を使用します)どうすればこの仕事をすることができますか?私はCodeigniterを使用します。あなたの時間と労力のため

おかげで、あなたは各反復で$menu[$type_id]['brands']配列を上書きしている

挨拶

+0

注: のみ最後BRAND_NAMEが表示されます。タイプが正しく機能しています。 – Loed

答えて

0

。私はあなたが意味を考える -

foreach($products as $product) { 

    $menu[$product['type_id']]['type'] = array (
     'url' => base_url('index.php/productcontroller/getProductList/'.$product['type_id']), 
     'type_name' => $types[$product['type_id']] 
    ); 

    // Brands 
    $menu[$product['type_id']]['brands'][$product['brand_id']]['brand'] = array(
     'url' => base_url('index.php/productcontroller/getProductList/'.$product['type_id'].'/'.$product['brand_id']), 
     'brand_name' => $brands[$product['brand_id']] 
    ); 

} 
+0

あなたは絶対に正しいです!どうもありがとうございました。私が何を間違えたか教えてください。 – Loed

+0

私が答えて言ったように、あなたは各繰り返しで配列を上書きしていました - '$ menu [$ type [type_id ']] [' brands '] = array(' – nnichols

+0

私はそれに気付かなかった、 – Loed

関連する問題