在$ _POST上写一个DB内的数组,就像结果一样

时间:2018-06-04 01:47:52

标签: php

我在$weight_class_title上遇到了问题。 保存数据后,它会在数据库数组中写入。

Tk的。

var_dump($sql_data_array);

的结果
array (size=4)
  'weight_class_title' => 
    array (size=1)
      'weight_class_title' => string 'tt' (length=2)
  'weight_class_key' => string 'pound' (length=5)
  'weight_class_id' => int 5
  'language_id' => int 1

array (size=4)
  'weight_class_title' => 
    array (size=1)
      'weight_class_title' => string 'tt' (length=2)
  'weight_class_key' => string 'pound' (length=5)
  'weight_class_id' => int 5
  'language_id' => int 2


  public function execute()  {
   $CLICSHOPPING_Language = Registry::get('Language');
   $CLICSHOPPING_Db = Registry::get('Db');
   $languages = $CLICSHOPPING_Language->getLanguages();

    $QlastId = $CLICSHOPPING_Db->prepare('select weight_class_id 
                                          from :table_weight_classes 
                                          order by weight_class_id desc
                                          limit 1');
    $QlastId->execute();

    $weight_class_id = $QlastId->valueInt('weight_class_id') + 1;
    $weight_class_key = $_POST['weight_class_key'];

    for ($i=0, $n=count($languages); $i<$n; $i++) {
      $weight_class_title_array = $_POST['weight_class_title'];
      $language_id = $languages[$i]['id'];

      $weight_class_title_array = ['weight_class_title' => HTML::sanitize($weight_class_title_array[$language_id])];

       $sql_data_array = ['weight_class_title' => $weight_class_title_array];

      $insert_sql_data = ['weight_class_key' => $weight_class_key,
                          'weight_class_id' => $weight_class_id,
                          'language_id' => $languages[$i]['id']
                         ];

      $sql_data_array = array_merge($sql_data_array, $insert_sql_data);

      $this->app->db->save('weight_classes', $sql_data_array);
    }

0 个答案:

没有答案