IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PHP & Base de données Discussion :

Foreach et select


Sujet :

PHP & Base de données

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2011
    Messages
    131
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Mars 2011
    Messages : 131
    Par défaut Foreach et select
    Bonjour,

    Depuis plusieurs jours je me fracasse la tête sur ce script ou je n'arrive pas à trouver de solution.
    Le problème est d'arriver à créer différents select html avec les bonnes valeurs.
    Actuellement les select sont crées et dupliqués à chaque fois avec des valeurs qui s'ajoutent !
    Pour créer une liste d'options de produit, cela ne fonctionne pas

    Si avez une idées pour arriver le le bon rendu, je suis preneur (cf 2/)


    Merci de votre aide.


    Si vous avez besoins compléments d'information notamment de données, n'hésitez pas.

    Comme vous pouvez le voir actuellement le rendu est comme ceci :

    1/ rendu actuel : cf https://jsfiddle.net/8zbqxyqo/2/

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    <div class="form-group">
    <div class="form-group">
    <label class="control-label" for="input-option">Couleur</label>
    <select name="option[]" id="input-option" class="form-control">
    <option value="">--- Selectioner ---</option>
    <option value=""> Red() + : 50</option>
    </select>
    </div>
    <div class="form-group">
    <label class="control-label" for="input-option">Couleur</label>
    <select name="option[]" id="input-option" class="form-control">
    <option value="">--- Selectioner ---</option>
    <option value=""> Red() + : 50</option>
    <option value=""> Vert() </option>
    </select>
    </div>
    <div class="form-group">
    <label class="control-label" for="input-option">Taille</label>
    <select name="option[]" id="input-option" class="form-control">
    <option value="">--- Selectioner ---</option>
    <option value=""> Red() + : 50</option>
    <option value=""> Vert() </option>
    <option value=""> S() </option>
    </select>
    </div>
    <div class="form-group">
    <label class="control-label" for="input-option">Taille</label>
    <select name="option[]" id="input-option" class="form-control">
    <option value="">--- Selectioner ---</option>
    <option value=""> Red() + : 50</option>
    <option value=""> Vert() </option>
    <option value=""> S() </option>
    <option value=""> M() + : 20</option>
    </select>
    </div>
    </div>
    2 / voici le bon rendu qui doit être généré :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    <div class="form-group">
    <label class="control-label" for="input-option">Couleur</label>
    <select name="option[1]" id="input-option1" class="form-control">
    <option value="">--- Selectioner ---</option>
    <option value=""> Red() + : 50</option>
    <option value=""> Vert() </option>
    </select>
    </div>
     
    <div class="form-group">
    <label class="control-label" for="input-option">Taille</label>
    <select name="option[2]" id="input-option2" class="form-control">
    <option value="">--- Selectioner ---</option>
    <option value=""> S() </option>
    <option value=""> M() + : 20</option>
    </select>
    </div>

    Voici le code php en conséquence avec les informations complémentaires pour vous aider.

    la fonction

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
     
    public function getProductOptions($product_id) {
          $QproductOption = $this->db->prepare('select * 
                                                from :table_test_products_option po left join :table_test_products_options_attributes o ON (po.option_id = o.option_id) 
                                                                                    left join :table_test_products_options_attributes_description od ON (o.option_id = od.option_id) 
                                                where po.products_id = :products_id
                                                and od.language_id = :language_id
                                                order by o.sort_order
                                                ');
     
          $QproductOption->bindInt(':products_id', $product_id );
          $QproductOption->bindInt(':language_id', $this->lang->getId());
          $QproductOption->execute();
     
          $products_option = $QproductOption->fetchAll();
     
          foreach ($products_option as $key => $product_option) {
     
            $QproductOptionValue = $this->db->prepare('select * 
                                                       from :table_test_products_option_value pov left join :table_test_products_options_attributes_value ov ON (pov.option_value_id = ov.option_value_id) 
                                                                                                  left join :table_test_products_options_attributes_value_description ovd ON (ov.option_value_id = ovd.option_value_id) 
                                                      where pov.products_id = :products_id
                                                      and pov.products_option_id = :products_option_id
                                                      and ovd.language_id = :language_id
                                                      order by ov.sort_order
                                                      ');
     
            $QproductOptionValue->bindInt(':products_id', $product_id );
            $QproductOptionValue->bindInt(':language_id', $this->lang->getId());
            $QproductOptionValue->bindInt(':products_option_id', $product_option['products_option_id']);
            $QproductOptionValue->execute();
     
            $product_option_value = $QproductOptionValue->fetchAll();
     
            foreach ($product_option_value as  $pov => $products_value) {
              $product_option_value_data[] = ['products_option_value_id' => $products_value['products_option_value_id'],
                                              'option_value_id'         => $products_value['option_value_id'],
                                              'name'                    => $products_value['name'],
                                              'image'                   => $products_value['image'],
                                              'quantity'                => $products_value['quantity'],
                                              'subtract'                => $products_value['subtract'],
                                              'price'                   => $products_value['price'],
                                              'price_prefix'            => $products_value['price_prefix'],
                                              'weight'                  => $products_value['weight'],
                                              'weight_prefix'           => $products_value['weight_prefix'],
                                              'customers_group_id'      => $products_value['customers_group_id'],
                                              'products_option_model'   => $products_value['products_option_model'],
                                              'option_tax_class_id'     => $products_value['option_tax_class_id']
                                            ];
            }
     
            $product_option_data[] = [
                                      'products_option_id'    => $product_option['products_option_id'],
                                      'option_id'            => $product_option['option_id'],
                                      'name'                 => $product_option['name'],
                                      'type'                 => $product_option['type'],
                                      'value'                => $product_option['value'],
                                      'required'             => $product_option['required'],
                                      'products_option_value' => $product_option_value_data
                                    ];
          }
     
          return $product_option_data;
        }

    résultat de $product_option_value_data


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
     
    array (size=1)
      0 => 
        array (size=13)
          'products_option_value_id' => string '283' (length=3)
          'option_value_id' => string '187' (length=3)
          'name' => string 'Red' (length=3)
          'image' => null
          'quantity' => string '200' (length=3)
          'subtract' => string '0' (length=1)
          'price' => string '50.0000' (length=7)
          'price_prefix' => string '+' (length=1)
          'weight' => string '0.00' (length=4)
          'weight_prefix' => string '+' (length=1)
          'customers_group_id' => string '0' (length=1)
          'products_option_model' => string '' (length=0)
          'option_tax_class_id' => string '0' (length=1)
     
    array (size=2)
      0 => 
        array (size=13)
          'products_option_value_id' => string '283' (length=3)
          'option_value_id' => string '187' (length=3)
          'name' => string 'Red' (length=3)
          'image' => null
          'quantity' => string '200' (length=3)
          'subtract' => string '0' (length=1)
          'price' => string '50.0000' (length=7)
          'price_prefix' => string '+' (length=1)
          'weight' => string '0.00' (length=4)
          'weight_prefix' => string '+' (length=1)
          'customers_group_id' => string '0' (length=1)
          'products_option_model' => string '' (length=0)
          'option_tax_class_id' => string '0' (length=1)
      1 => 
        array (size=13)
          'products_option_value_id' => string '282' (length=3)
          'option_value_id' => string '186' (length=3)
          'name' => string 'Vert' (length=4)
          'image' => null
          'quantity' => string '0' (length=1)
          'subtract' => string '0' (length=1)
          'price' => string '0.0000' (length=6)
          'price_prefix' => string '+' (length=1)
          'weight' => string '0.00' (length=4)
          'weight_prefix' => string '+' (length=1)
          'customers_group_id' => string '0' (length=1)
          'products_option_model' => string '' (length=0)
          'option_tax_class_id' => string '0' (length=1)
     
    array (size=3)
      0 => 
        array (size=13)
          'products_option_value_id' => string '283' (length=3)
          'option_value_id' => string '187' (length=3)
          'name' => string 'Red' (length=3)
          'image' => null
          'quantity' => string '200' (length=3)
          'subtract' => string '0' (length=1)
          'price' => string '50.0000' (length=7)
          'price_prefix' => string '+' (length=1)
          'weight' => string '0.00' (length=4)
          'weight_prefix' => string '+' (length=1)
          'customers_group_id' => string '0' (length=1)
          'products_option_model' => string '' (length=0)
          'option_tax_class_id' => string '0' (length=1)
      1 => 
        array (size=13)
          'products_option_value_id' => string '282' (length=3)
          'option_value_id' => string '186' (length=3)
          'name' => string 'Vert' (length=4)
          'image' => null
          'quantity' => string '0' (length=1)
          'subtract' => string '0' (length=1)
          'price' => string '0.0000' (length=6)
          'price_prefix' => string '+' (length=1)
          'weight' => string '0.00' (length=4)
          'weight_prefix' => string '+' (length=1)
          'customers_group_id' => string '0' (length=1)
          'products_option_model' => string '' (length=0)
          'option_tax_class_id' => string '0' (length=1)
      2 => 
        array (size=13)
          'products_option_value_id' => string '281' (length=3)
          'option_value_id' => string '179' (length=3)
          'name' => string 'S' (length=1)
          'image' => null
          'quantity' => string '0' (length=1)
          'subtract' => string '0' (length=1)
          'price' => string '0.0000' (length=6)
          'price_prefix' => string '+' (length=1)
          'weight' => string '0.00' (length=4)
          'weight_prefix' => string '+' (length=1)
          'customers_group_id' => string '0' (length=1)
          'products_option_model' => string '' (length=0)
          'option_tax_class_id' => string '0' (length=1)
     
     
    array (size=4)
      0 => 
        array (size=13)
          'products_option_value_id' => string '283' (length=3)
          'option_value_id' => string '187' (length=3)
          'name' => string 'Red' (length=3)
          'image' => null
          'quantity' => string '200' (length=3)
          'subtract' => string '0' (length=1)
          'price' => string '50.0000' (length=7)
          'price_prefix' => string '+' (length=1)
          'weight' => string '0.00' (length=4)
          'weight_prefix' => string '+' (length=1)
          'customers_group_id' => string '0' (length=1)
          'products_option_model' => string '' (length=0)
          'option_tax_class_id' => string '0' (length=1)
      1 => 
        array (size=13)
          'products_option_value_id' => string '282' (length=3)
          'option_value_id' => string '186' (length=3)
          'name' => string 'Vert' (length=4)
          'image' => null
          'quantity' => string '0' (length=1)
          'subtract' => string '0' (length=1)
          'price' => string '0.0000' (length=6)
          'price_prefix' => string '+' (length=1)
          'weight' => string '0.00' (length=4)
          'weight_prefix' => string '+' (length=1)
          'customers_group_id' => string '0' (length=1)
          'products_option_model' => string '' (length=0)
          'option_tax_class_id' => string '0' (length=1)
      2 => 
        array (size=13)
          'products_option_value_id' => string '281' (length=3)
          'option_value_id' => string '179' (length=3)
          'name' => string 'S' (length=1)
          'image' => null
          'quantity' => string '0' (length=1)
          'subtract' => string '0' (length=1)
          'price' => string '0.0000' (length=6)
          'price_prefix' => string '+' (length=1)
          'weight' => string '0.00' (length=4)
          'weight_prefix' => string '+' (length=1)
          'customers_group_id' => string '0' (length=1)
          'products_option_model' => string '' (length=0)
          'option_tax_class_id' => string '0' (length=1)
      3 => 
        array (size=13)
          'products_option_value_id' => string '280' (length=3)
          'option_value_id' => string '180' (length=3)
          'name' => string 'M' (length=1)
          'image' => null
          'quantity' => string '100' (length=3)
          'subtract' => string '0' (length=1)
          'price' => string '20.0000' (length=7)
          'price_prefix' => string '+' (length=1)
          'weight' => string '0.00' (length=4)
          'weight_prefix' => string '+' (length=1)
          'customers_group_id' => string '0' (length=1)
          'products_option_model' => string '' (length=0)
          'option_tax_class_id' => string '0' (length=1)


    résultat de $product_option_data


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
     
    array (size=4)
      0 => 
        array (size=7)
          'products_option_id' => string '410' (length=3)
          'option_id' => string '42' (length=2)
          'name' => string 'Couleur' (length=7)
          'type' => string 'select' (length=6)
          'value' => null
          'required' => null
          'products_option_value' => 
            array (size=1)
              0 => 
                array (size=13)
                  ...
      1 => 
        array (size=7)
          'products_option_id' => string '409' (length=3)
          'option_id' => string '42' (length=2)
          'name' => string 'Couleur' (length=7)
          'type' => string 'select' (length=6)
          'value' => null
          'required' => null
          'products_option_value' => 
            array (size=2)
              0 => 
                array (size=13)
                  ...
              1 => 
                array (size=13)
                  ...
      2 => 
        array (size=7)
          'products_option_id' => string '408' (length=3)
          'option_id' => string '40' (length=2)
          'name' => string 'Taille' (length=6)
          'type' => string 'select' (length=6)
          'value' => null
          'required' => null
          'products_option_value' => 
            array (size=3)
              0 => 
                array (size=13)
                  ...
              1 => 
                array (size=13)
                  ...
              2 => 
                array (size=13)
                  ...
      3 => 
        array (size=7)
          'products_option_id' => string '407' (length=3)
          'option_id' => string '40' (length=2)
          'name' => string 'Taille' (length=6)
          'type' => string 'select' (length=6)
          'value' => null
          'required' => null
          'products_option_value' => 
            array (size=4)
              0 => 
                array (size=13)
                  ...
              1 => 
                array (size=13)
                  ...
              2 => 
                array (size=13)
                  ...
              3 => 
                array (size=13)
                  ...


    génération du code côté front office :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
     
              $data['options'] = [];
     
              $options_array = $this->ProductsAttributesShop->getProductOptions($OSCOM_ProductsCommon->getID());
     
              foreach ($options_array as $option) {
                $product_option_value_data = [];
     
                foreach ($option['products_option_value'] as $option_value) {
                  if (isset($option_value['subtract']) || $option_value['quantity'] > 0) {
                      if ($option_value['price'] > 0) {
                        $price = (float)$option_value['price'];// inclure la taxe
                      } else {
                        $price = false;
                      }
     
                      $product_option_value_data[] =  ['products_option_value_id' => $option_value['products_option_value_id'],
                                                       'option_value_id'         => $option_value['option_value_id'],
                                                       'name'                    => $option_value['name'],
                                                       'image'                   => $option_value['image'],
                                                       'quantity'                => $option_value['quantity'],
                                                       'price'                   => $price,
                                                       'price_prefix'            => $option_value['price_prefix'],
                                                       'weight'                  => $option_value['weight'],
                                                       'weight_prefix'           => $option_value['weight_prefix'],
                                                       'customers_group_id'      => $option_value['customers_group_id'],
                                                       'products_option_model'   => $option_value['products_option_model'],
                                                      ];
                  }
                }
     
                $data['options'][] = [
                                      'products_option_id'    => $option['products_option_id'],
                                      'option_id'            => $option['option_id'],
                                      'name'                 => $option['name'],
                                      'type'                 => $option['type'],
                                      'value'                => $option['value'],
                                      'required'             => $option['required'],
                                      'products_option_value' => $product_option_value_data
                                      ];
              }
     
              $products_options_content_display .= ' <div>';
     
    //******************************************
    // select
    //******************************************
             $products_options_content_display .= '<div class="form-group">'; 
     
              if ($data['options']) {
                $test = '';
     
                foreach ($data['options'] as $key => $option) {
                  if ($option['type'] == 'select') {
                    if ($option['required'] == 1) $required = ' required';
     
                    $test .= '<div class="form-group' . $required . '">';
                    $test .= '<label class="control-label" for="input-option' . $option['product_option_id'] . '">' . $option['name'] . '</label>';
                    $test .= '<select name="option[' . $option['product_option_id'] . ']" id="input-option' . $option['product_option_id'] . ' class="form-control">';
                    $test .= '<option value="">' . OSCOM::getDef('text_select') . '</option>';
     
                    foreach ($option['products_option_value'] as $t => $option_value) {
                      $test .= '<option value="' .  $option_value['product_option_value_id'] . '"> ' . $option_value['name'];
     
                      if (!is_null($option_value['products_option_model'])) {
                        $model = $option_value['products_option_model'];
                        $test .= '(' . $model . ') ';
                      }
     
                      if ($option_value['price'] > 0) {
                        $test .= $option_value['price_prefix'] . ' : ' . $option_value['price'];
                      }
     
                      $test .='</option>';
                    }
     
                    $test .= '</select>';
                    $test .= '</div>';
                  }
                }
              }
     
              $products_options_content_display .= $test;
     
             echo $products_options_content_display;

  2. #2
    Expert confirmé
    Avatar de rawsrc
    Homme Profil pro
    Dev indep
    Inscrit en
    Mars 2004
    Messages
    6 142
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Dev indep

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 142
    Billets dans le blog
    12
    Par défaut
    Salut,

    sans accès aux données, difficile de creuser.
    Je pense que le problème se situe au niveau des requêtes SQL.
    Il me semble que les données à afficher contiennent déjà le souci $options_array = $this->ProductsAttributesShop->getProductOptions($OSCOM_ProductsCommon->getID());.
    Exécute tes requêtes SQL en dehors du code est vérifie que les données retournées sont propres.

  3. #3
    Modératrice
    Avatar de Celira
    Femme Profil pro
    Développeuse PHP/Java
    Inscrit en
    Avril 2007
    Messages
    8 633
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeuse PHP/Java
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2007
    Messages : 8 633
    Par défaut
    Hum.. Les <select> sont alimentés par $data['options'] si je vois bien. On peut voir le contenu de $data['options'] juste avant la boucle qui s'en sert ?
    Modératrice PHP
    Aucun navigateur ne propose d'extension boule-de-cristal : postez votre code et vos messages d'erreurs. (Rappel : "ça ne marche pas" n'est pas un message d'erreur)
    Cherchez un peu avant poser votre question : Cours et Tutoriels PHP - FAQ PHP - PDO une soupe et au lit !.

    Affichez votre code en couleurs : [CODE=php][/CODE] (bouton # de l'éditeur) et [C=php][/C]

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2011
    Messages
    131
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Mars 2011
    Messages : 131
    Par défaut
    Merci,

    J'en ai profité pour regardé encore une fois. A priori, j'aurais un duplicate de donnéessur une requête. je vais creuser la dessus, peut être qu'au niveau de l'enregistrement cela ne se passe pas comme voulu.
    je te reviens plus tard.

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2011
    Messages
    131
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Mars 2011
    Messages : 131
    Par défaut
    @rawsrc

    Oui j'avais un pb sur une des tables : après fait la modification, j'ai toujours le même problème côté front office.

    Pour le moment j'ai fait qu'un select sur lequel il doit recevoir 2 types de valeurs (taille M et une taille s).
    Comme vous pouvez le constater il me crée 2 select alors que je devrais en avoir qu'un

    Voici ce que cela donne


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    <div class="form-group">
    <label class="control-label" for="input-option">Taille</label>
    <select name="option[]" id="input-option" class="form-control">
    <option value="">--- Selectioner ---</option>
    <option value=""> M() + : 10</option>
    </select>
    </div>
    <div class="form-group">
    <label class="control-label" for="input-option">Taille</label>
    <select name="option[]" id="input-option" class="form-control">
    <option value="">--- Selectioner ---</option>
    <option value=""> M() + : 10</option>
    <option value=""> S() + : 20</option>
    </select>
    </div>
    @Celira

    Voici les éléments que tu me demandes.
    C'est mis au format json


    contenu de de la fonction :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
     
    [
       {
          "products_option_id":"1",
          "option_id":"40",
          "name":"Taille",
          "type":"select",
          "value":null,
          "required":"0",
          "products_option_value":[
             {
                "products_option_value_id":"284",
                "option_value_id":"180",
                "name":"M",
                "image":null,
                "quantity":"0",
                "subtract":"0",
                "price":"10.0000",
                "price_prefix":"+",
                "weight":"0.00",
                "weight_prefix":"+",
                "customers_group_id":"0",
                "products_option_model":"",
                "option_tax_class_id":"0"
             }
          ]
       },
       {
          "products_option_id":"2",
          "option_id":"40",
          "name":"Taille",
          "type":"select",
          "value":null,
          "required":"0",
          "products_option_value":[
             {
                "products_option_value_id":"284",
                "option_value_id":"180",
                "name":"M",
                "image":null,
                "quantity":"0",
                "subtract":"0",
                "price":"10.0000",
                "price_prefix":"+",
                "weight":"0.00",
                "weight_prefix":"+",
                "customers_group_id":"0",
                "products_option_model":"",
                "option_tax_class_id":"0"
             },
             {
                "products_option_value_id":"285",
                "option_value_id":"179",
                "name":"S",
                "image":null,
                "quantity":"0",
                "subtract":"0",
                "price":"20.0000",
                "price_prefix":"+",
                "weight":"0.00",
                "weight_prefix":"+",
                "customers_group_id":"0",
                "products_option_model":"",
                "option_tax_class_id":"0"
             }
          ]
       }
    ]

    Contenu de $data['options']

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    Array ( [0] => Array ( [products_option_id] => 1 [option_id] => 40 [name] => Taille [type] => select [value] => [required] => 0 
     
    [products_option_value] => 
    Array ( 
    [0] => Array ( [products_option_value_id] => 284 [option_value_id] => 180 [name] => M [image] => [quantity] => 0 [price] => 10 [price_prefix] => + [weight] => 0.00 [weight_prefix] => + [customers_group_id] => 0 [products_option_model] => 
    ) ) ) 
     
    [1] => Array ( [products_option_id] => 2 [option_id] => 40 [name] => Taille [type] => select [value] => [required] => 0 
     
    [products_option_value] => 
    Array ( [0] => Array ( [products_option_value_id] => 284 [option_value_id] => 180 [name] => M [image] => [quantity] => 0 [price] => 10 [price_prefix] => + [weight] => 0.00 [weight_prefix] => + [customers_group_id] => 0 [products_option_model] => ) 
    [1] => Array ( [products_option_value_id] => 285 [option_value_id] => 179 [name] => S [image] => [quantity] => 0 [price] => 20 [price_prefix] => + [weight] => 0.00 [weight_prefix] => + [customers_group_id] => 0 [products_option_model] => 
    ) ) ) )

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2011
    Messages
    131
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Mars 2011
    Messages : 131
    Par défaut
    [QUOTE=rawsrc;10003252]
    Pour info, cf ma réponse au 2 questions

  7. #7
    Modératrice
    Avatar de Celira
    Femme Profil pro
    Développeuse PHP/Java
    Inscrit en
    Avril 2007
    Messages
    8 633
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeuse PHP/Java
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2007
    Messages : 8 633
    Par défaut
    Hum... le script créée 2 selects, parce que ton tableau $data['options'] contient deux blocs, parce que $product_option_data contient 2 blocs. Donc le problème est sur la récupération des données, dans la fonction getProductOptions.

    Tes requêtes contiennent des left join, ce qui implique que tu peux remonter plusieurs fois la même donnée.
    Pour explication si on a une table Utilisateur, une table Commande et une table Produit, avec 2 Commandes de 2 Produits chacune, en faisant Utilisateur left join Commande left joint Produit on va récupérer quelque chose comme
    User1 | Commande1 | ProduitA
    User1 | Commande1 | ProduitB
    User1 | Commande2 | ProduitC
    User1 | Commande2 | ProduitD
    Et si on ne fait pas attention en bouclant, on peut se retrouver les infos de Commande en double.

    Vérifie en exécutant tes requêtes directement en base que ce n'est pas le cas.

    Au passage : utiliser SELECT * est certes très pratique, mais ce n'est pas forcément une bonne idée, parce que tu ne maîtrises pas ce qui est récupéré, et que tu peux remonter 25 colonnes pour 2 informations réellement nécessaires.
    Modératrice PHP
    Aucun navigateur ne propose d'extension boule-de-cristal : postez votre code et vos messages d'erreurs. (Rappel : "ça ne marche pas" n'est pas un message d'erreur)
    Cherchez un peu avant poser votre question : Cours et Tutoriels PHP - FAQ PHP - PDO une soupe et au lit !.

    Affichez votre code en couleurs : [CODE=php][/CODE] (bouton # de l'éditeur) et [C=php][/C]

  8. #8
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2011
    Messages
    131
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Mars 2011
    Messages : 131
    Par défaut
    Citation Envoyé par Celira Voir le message
    Hum... le script créée 2 selects......
    Ok, j'ai vu que j'avais un problème d'enregistrement de mes données coté admin, donc je vais regarder ca de plus prêt.
    merci pour l'orientation.
    Je vous reviens d'ici quelques jours.

  9. #9
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    Citation Envoyé par Celira Voir le message
    ...utiliser SELECT * est certes très pratique, mais ce n'est pas forcément une bonne idée, parce que tu ne maîtrises pas ce qui est récupéré, et que tu peux remonter 25 colonnes pour 2 informations réellement nécessaires.
    Je rejoins Celira.

    Quand on voit le résultat que tu attends (des <select>, avec name, option value et option titre, soit 3 données à trier !), on se demande pourquoi tu enregistres autant de données dans tes array ??

    Tu aurais tout intérêt à simplifier les requêtes (et les array) pour ne sortir QUE les données nécessaires.

    D'autant qu'on devrait pouvoir faire UNE SEULE requête, avec la commande SQL GROUP BY.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. pour les pro de développement (joomla,php,ajax) xD
    Par Arsofts dans le forum Général Conception Web
    Réponses: 0
    Dernier message: 21/07/2010, 14h33
  2. petit conseil pour les index
    Par fpouget dans le forum Langage SQL
    Réponses: 11
    Dernier message: 10/12/2005, 04h39
  3. Petit prog pour éxécuter un script PHP
    Par Sub0 dans le forum Contribuez / Téléchargez Sources et Outils
    Réponses: 3
    Dernier message: 26/04/2005, 15h53
  4. Réponses: 6
    Dernier message: 28/09/2004, 16h47
  5. Une petite aide pour les API ?
    Par Yop dans le forum Windows
    Réponses: 2
    Dernier message: 04/04/2002, 21h45

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo