重复选择内部循环

时间:2018-02-09 14:47:04

标签: php arrays

我有一个问题,只显示1个选择html元素内的所有数据。实际上我有三个选择元素处理分离数据。 元素和价格必须在一起,而不是在2中选择分开。

我希望找到一个解决方案而且我被封锁了。

我有一些重复元素的结果。 有关HTML的完整结果,请点击以下链接:https://jsfiddle.net/3ts9pkoe/1/

谢谢。

<option value="91">M</option>
 <option value="91">M</option>
 <option value="91">M</option>
 <option value="91">M</option>
 <option value="91">M</option>
 <option value="91">M</option

php代码(新方法):

              $options = $data['options'];
var_dump($options);

    array (size=4)
      0 => 
        array (size=7)
          'products_option_id' => string '106' (length=3)
          'products_option_value' => 
            array (size=10)
              'products_option_value_id' => string '91' (length=2)
              '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 '0.0000' (length=6)
              'price_prefix' => string '+' (length=1)
              'weight' => string '0.00' (length=4)
              'weight_prefix' => string '+' (length=1)
          'option_id' => string '40' (length=2)
          'name' => string 'Taille' (length=6)
          'type' => string 'select' (length=6)
          'value' => null
          'required' => null
      1 => 
        array (size=7)
          'products_option_id' => string '105' (length=3)
          'products_option_value' => 
            array (size=10)
              'products_option_value_id' => string '90' (length=2)
              'option_value_id' => string '179' (length=3)
              'name' => string 'S' (length=1)
              'image' => null
              'quantity' => string '100' (length=3)
              'subtract' => string '0' (length=1)
              'price' => string '1.0000' (length=6)
              'price_prefix' => string '+' (length=1)
              'weight' => string '0.00' (length=4)
              'weight_prefix' => string '+' (length=1)
          'option_id' => string '40' (length=2)
          'name' => string 'Taille' (length=6)
          'type' => string 'select' (length=6)
          'value' => null
          'required' => null
      2 => 
        array (size=7)
          'products_option_id' => string '104' (length=3)
          'products_option_value' => 
            array (size=10)
              'products_option_value_id' => string '89' (length=2)
              'option_value_id' => string '177' (length=3)
              'name' => string 'bleu' (length=4)
              'image' => null
              'quantity' => string '100' (length=3)
              'subtract' => string '0' (length=1)
              'price' => string '10.0000' (length=7)
              'price_prefix' => string '+' (length=1)
              'weight' => string '0.00' (length=4)
              'weight_prefix' => string '+' (length=1)
          'option_id' => string '38' (length=2)
          'name' => string 'Couleur' (length=7)
          'type' => string 'radio' (length=5)
          'value' => null
          'required' => null
      3 => 
        array (size=7)
          'products_option_id' => string '103' (length=3)
          'products_option_value' => 
            array (size=10)
              'products_option_value_id' => string '88' (length=2)
              'option_value_id' => string '178' (length=3)
              'name' => string 'green' (length=5)
              'image' => null
              'quantity' => string '50' (length=2)
              '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)
          'option_id' => string '38' (length=2)
          'name' => string 'Couleur' (length=7)
          'type' => string 'radio' (length=5)
          'value' => null
          'required' => null


          foreach ($options as $option) {
//SELECT
            if ($option['type'] == 'select') {
              $products_options_content_display .= ' <div class="form-group">'; // required or not
              $products_options_content_display .= '<label class="control-label" for="input-option' . $option['products_option_id'] . '">' .  $option['name'] . '</label>';
              $products_options_content_display .=' <select name="products_option_id' . $option['products_option_id'] . '" id="input-option' . $option['products_option_id'] . '" class="form-control">
                                                      <option value="">' . OSCOM::getDef('text_select') . '</option>
                                                     ';


  var_dump($option['products_option_value']);

array (size=10)
  'products_option_value_id' => string '91' (length=2)
  '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 '0.0000' (length=6)
  'price_prefix' => string '+' (length=1)
  'weight' => string '0.00' (length=4)
  'weight_prefix' => string '+' (length=1)

array (size=10)
  'products_option_value_id' => string '90' (length=2)
  'option_value_id' => string '179' (length=3)
  'name' => string 'S' (length=1)
  'image' => null
  'quantity' => string '100' (length=3)
  'subtract' => string '0' (length=1)
  'price' => string '1.0000' (length=6)
  'price_prefix' => string '+' (length=1)
  'weight' => string '0.00' (length=4)
  'weight_prefix' => string '+' (length=1)

array (size=10)
  'products_option_value_id' => string '89' (length=2)
  'option_value_id' => string '177' (length=3)
  'name' => string 'bleu' (length=4)
  'image' => null
  'quantity' => string '100' (length=3)
  'subtract' => string '0' (length=1)
  'price' => string '10.0000' (length=7)
  'price_prefix' => string '+' (length=1)
  'weight' => string '0.00' (length=4)
  'weight_prefix' => string '+' (length=1)

array (size=10)
  'products_option_value_id' => string '88' (length=2)
  'option_value_id' => string '178' (length=3)
  'name' => string 'green' (length=5)
  'image' => null
  'quantity' => string '50' (length=2)
  '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)



              foreach ($option['products_option_value'] as $value) {
                $products_options_content_display .= '<option value="' . $option['products_option_value']['products_option_value_id'] . '">' . $option['products_option_value']['name'];
                if ($option['products_option_value']['price']) {
                  $products_options_content_display .=  $option['products_option_value']['price_prefix'] .' ' . $option['products_option_value']['price'];
                }
                $products_options_content_display .= '</option>';

              }

              $products_options_content_display .= '</select>';
            }


//radio
            if ($option['type'] == 'radio') {
              $products_options_content_display .= ' <div class="form-group">'; // required or not
              $products_options_content_display .= '<label class="control-label" for="input-option' . $option['products_option_id'] . '">' .  $option['name'] . '</label>';

              foreach ($option['products_option_value'] as $value) {
                $products_options_content_display .= '<li><input type="radio" name="' . $option['products_option_value']['name'] . '" value="' . $option['products_option_value']['products_option_value_id'] . '">';
//                {% if option_value.image %} <img src="{{ option_value.image }}" alt="{{ option_value.name }} {% if option_value.price %} {{ option_value.price_prefix }} {{ option_value.price }} {% endif %}" class="img-thumbnail" /> {% endif %}
                $products_options_content_display .= $option['products_option_value']['name'];

                if ($option['products_option_value']['price']) {
                  $products_options_content_display .=  $option['products_option_value']['price_prefix'] .' ' . $option['products_option_value']['price'];
                }
                '</li>';
              }
            }
          }

0 个答案:

没有答案