How to insert multiple dynamic rows into the database
<p>I have a multiple row dynamic table that I created using php and jQuery. Here's <a href="https://jsfiddle.net/soumyar/c8w2Lrk8/" rel="nofollow noreferrer">the link to view the table</a>.</p>

<p>Everything is working fine except when I insert the data into the database, the serial numbers do not save sequentially. My insert queries are as below:</p>

<pre><code>for($i = 0; $i &lt; count($_POST['C_Objectives']); $i++)
{
    $sql = "INSERT INTO Appraisal_Objectives (Serial_Number,Objectives,Measures,Targets,subtotal,Corporate_Objective,Row_Number,ID) Values ('$formno','||&lt;==','==','==','".$_POST['SubTotals'][$i]."','".$_POST['C_Objectives'][$i]."','".$_POST['SNo'][$i]."','$statement')";
    $stmt = sqlsrv_query($conn, $sql);
    if($stmt === false)
        die(print_r(sqlsrv_errors(), true));
    else
        echo " ";
}

for($i = 0; $i &lt; count($_POST['Measures']); $i++)
{
    $sql = "INSERT INTO Appraisal_Objectives (Serial_Number,Objectives,Measures,Targets,Weightage,Row_Number,target_date,ID) VALUES ('$formno','".$_POST['Objectives'][$i]."','".$_POST['Measures'][$i]."','".$_POST['Achievement'][$i]."','".$_POST['Weightage_Target'][$i]."','".$_POST['SNo'][$i]."','".$_POST['Date_Target'][$i]."','$statement')"; 
    $stmt = sqlsrv_query($conn, $sql);
    if($stmt === false)
        die(print_r(sqlsrv_errors(), true));
    else
        echo " ";
}
</code></pre>

<p>The serial number is saved in the column <strong>Row_Number, using <code>$_POST['SNo'][$i]</code></strong>. Is it possible to save both of the dynamic rows using 1 insert query so that the serial numbers are saved sequentially?</p>

<p>This is the <code>$_POST</code> array result:</p>

<pre><code>    [Row_Number] =&gt; Array
        (
            [0] =&gt; 1
            [1] =&gt; 2
        )

    [C_Objectives] =&gt; Array
        (
            [0] =&gt; A
            [1] =&gt; B
        )

    [Objectives] =&gt; Array
        (
            [0] =&gt; a1
            [1] =&gt; a4
            [2] =&gt; a7
            [3] =&gt; b1
        )

    [Measures] =&gt; Array
        (
            [0] =&gt; a2
            [1] =&gt; a5
            [2] =&gt; a8
            [3] =&gt; b2
        )

    [Achievement] =&gt; Array
        (
            [0] =&gt; a3
            [1] =&gt; a6
            [2] =&gt; a9
            [3] =&gt; b3
        )

    [Date_Target] =&gt; Array
        (
            [0] =&gt; 2016-09-09
            [1] =&gt; 2016-09-09
            [2] =&gt; 2016-09-09
            [3] =&gt; 2016-09-09
        )

    [Weightage_Target] =&gt; Array
        (
            [0] =&gt; 25
            [1] =&gt; 25
            [2] =&gt; 25
            [3] =&gt; 25
        )

    [SNo] =&gt; Array
        (
            [0] =&gt; 3
            [1] =&gt; 4
            [2] =&gt; 5
            [3] =&gt; 6
        )

    [SubTotals] =&gt; Array
        (
            [0] =&gt; 75
            [1] =&gt; 25
        )

    [GrandTotal] =&gt; 100
)
</code></pre>

<p>I've also tried making the column auto-increment, but yet doesn't save the data in the same order as it is entered in the front end. </p>

<p><a href="https://i.stack.imgur.com/dWW21.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dWW21.png" alt="enter image description here"></a></p>

<p><a href="https://i.stack.imgur.com/ezOdd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ezOdd.png" alt="enter image description here"></a></p>