How to insert multiple text box value in one field with different different id?

前端 未结 2 1984
庸人自扰
庸人自扰 2021-01-29 04:12

Here is my code. It is insert only last element value. I want to insert all value in one field with different id and all data insert in different different row.



        
相关标签:
2条回答
  • 2021-01-29 05:03

    Change your sql for insert into this :

    function mysql_insert_multiple($db, $table, $columns) {
      $sql = "INSERT INTO `" . $table . "` ";
      // implode keys of $array...
      $sql .= " (`" . implode("`, `", array_keys($columns[0])) . "`)";
      // implode values of $array...
      $sql .= " VALUES ";
      $tempstr = array();
      foreach ($columns as $row) {
        $tempstr[] = " ('" . implode("', '", array_values($row)) . "') ";
        $sql.=implode(',', $tempstr);
        $sql.=";";
        $result = mysql_query($sql, $db) or die(mysql_error());
      }
    
      return $result;
    }
    

    This will work if your $column array is in the format:

    $columns = array(
        0 => array("name" => 'slider'
         "value" => $user_slider.
        1 => 
           .
           .
           .
    

    So I think you need to change your $column array as well.

    0 讨论(0)
  • 2021-01-29 05:09

    You can user your query with in a loop to insert the multiple recoded in a field at a time.

    0 讨论(0)
提交回复
热议问题