如何在输入元素中进行分组并使用php插入到mysql中?

时间:2021-03-25 07:36:26
<input type="text" id="reference_code" name="reference_code[]" required class="form-control" value="<?php echo set_value("reference_code"); ?>"/>

How to use multidimentional to insert into MySQL using PHP? Please check with my below code

如何使用PHP使用multidimentional插入MySQL?请查看我的以下代码

Array
(
    [reference] => asdf
    [company_id] => 25
    [contact] => Sam Deva
    [sales_manager_demand] => 1
    [team_leader_demand] => 11
    [demand_date] => 11-05-2015
    [target_date] => 27-05-2015
    [state] => 11
    [city] => 328
    [description] => asdfasdfsadfdsf
    [countdown1] => 485
    [reference_code] => Array
        (
            [0] => 200
            [1] => 300
        )
    [position] => Array
        (
            [0] => sales manager
            [1] => sales manager
        )

    [pri_skill_id] => Array
        (
            [0] => 2
            [1] => 7
        )

    [other_primary_tech] => Array
        (
            [0] => 
            [1] => 
        )

    [sec_skill_id] => Array
        (
            [0] => 2
            [1] => 5
        )

    [other_secondary_tech] => Array
        (
            [0] => 
            [1] => 
        )

    [minimum_experience] => Array
        (
            [0] => 23
            [1] => 12
        )

How to insert these values into MySQL using a single foreach

如何使用单个foreach将这些值插入MySQL

1 个解决方案

#1


$reference_code=$_POST['reference_code'];
$query="insert into tablename (reference,company_id,......,other_primary_tech) values "; //write insert with all the fields
$val="";
foreach($reference_code as $key=>$val){
$ref_code=$reference_code[$key];
$position=$_POST[position][$key];
$pri_skill_id=$_POST[pri_skill_id][$key];
$other_secondary_tech=$_POST[other_secondary_tech][$key];
$minimum_experience=$_POST[minimum_experience][$key];
$val.=" (".$_POST['reference'].",........,".$minimum_experience.")"; // values to insert
}

$query.=$val; //final query

You can try like this.....

你可以尝试这样.....

#1


$reference_code=$_POST['reference_code'];
$query="insert into tablename (reference,company_id,......,other_primary_tech) values "; //write insert with all the fields
$val="";
foreach($reference_code as $key=>$val){
$ref_code=$reference_code[$key];
$position=$_POST[position][$key];
$pri_skill_id=$_POST[pri_skill_id][$key];
$other_secondary_tech=$_POST[other_secondary_tech][$key];
$minimum_experience=$_POST[minimum_experience][$key];
$val.=" (".$_POST['reference'].",........,".$minimum_experience.")"; // values to insert
}

$query.=$val; //final query

You can try like this.....

你可以尝试这样.....