Javascript 使用PHP分解数组并识别要插入SQL的对象

Javascript 使用PHP分解数组并识别要插入SQL的对象,javascript,php,arrays,ajax,performance,Javascript,Php,Arrays,Ajax,Performance,我有一个JavaScript数组,它有多个对象。对象内部有多个元素。我正在尝试使用AJAX将这些元素插入PHP并插入SQL 我可以很好地将数组传递到PHP中,但是当我对数组进行编码并回显数据时,我有一堆字符串。我只需要分解这些元素并将它们插入SQL 如何使php与底部的“期望结果”类似,以便在一个查询中使用数据“SqlArr”将多行数据插入SQL 非常感谢您的帮助 HTML PHP 旁注:为什么您的查询被注释?因为我只想在插入值之前确保值的格式正确表示:为什么您的查询被注释?因为我只想在插入值之

我有一个JavaScript数组,它有多个对象。对象内部有多个元素。我正在尝试使用AJAX将这些元素插入PHP并插入SQL

我可以很好地将数组传递到PHP中,但是当我对数组进行编码并回显数据时,我有一堆字符串。我只需要分解这些元素并将它们插入SQL

如何使php与底部的“期望结果”类似,以便在一个查询中使用数据“SqlArr”将多行数据插入SQL

非常感谢您的帮助

HTML

PHP


旁注:为什么您的查询被注释?因为我只想在插入值之前确保值的格式正确表示:为什么您的查询被注释?因为我只想在插入值之前确保值的格式正确
<tr class="rows" id="row3" >
   <td class="celltimes4a"id="row3Project"></td>
   <td class="celltimes4c"id="row3Name">General</td>
   <td class="celltimes4"id="row3Sun" ><input id="num3Sun" class="alignRight"  type="text" name="hours" value="" onchange="tott(this)"></input></td>
   <td class="celltimes4"id="row3Mon" ><input id="num3Mon" class="alignRight" type="text" name="hours" value="" onchange="tott(this)"></input></td>
   <td class="celltimes4"id="row3Tue" ><input id="num3Tue" class="alignRight" type="text" name="hours" value="" onchange="tott(this)"></input></td>
   <td class="celltimes4"id="row3Wed" ><input id="num3Wed" class="alignRight" type="text" name="hours" value="" onchange="tott(this)"></input></td>
   <td class="celltimes4"id="row3Thu" ><input id="num3Thu" class="alignRight" type="text" name="hours" value="" onchange="tott(this)"></input></td>
   <td class="celltimes4"id="row3Fri" ><input id="num3Fri" class="alignRight" type="text" name="hours" value="" onchange="tott(this)"></input></td>
   <td class="celltimes4"id="row3Sat" ><input id="num3Sat" class="alignRight" type="text" name="hours" value="" onchange="tott(this)"></input></td>
   <td class="celltimes4b"id="total3"></td>
</tr>
function tott(element) {


    var totwLeg = element.id;
    var splitNumero = totwLeg.split(/([A-Za-z]+)([0-9]+)/);
    var getNumero = splitNumero[2];
    var getDay = splitNumero[3];


    EmpId = document.getElementById('num1').value;
    WkEnd = document.getElementById('theDate').value;
    Day = document.getElementById('row1' + getDay).innerHTML;
    Title = getNumero - 2;
    Description = getNumero - 2;
    Value = document.getElementById('num' + getNumero + getDay).value;
    AbbrevJob = Title;

    //Empdata = 'EmpData' + cnt + '';
    temp = {
        EmpId, WkEnd, Day, Title, Description, Value, AbbrevJob
    }; // this is where the columsn should match or go inside the columsn in the table... hold one moment
    SqlArr.push(temp);
    //JSON.stringify(SqlArr);


}

function saveMe() {
    $.post('php/GetEmployeeData.php', {
        'SqlArr': SqlArr,
        datatype: "json"
    }, function(SqlArr) {
        alert(SqlArr);
    })
}
<?php
include_once 'DbConnectPSI.php';
    global $connect;
    global $record3;
    global $myData3;

    $SqlArr =$_POST['SqlArr'];

    $SqlArr =json_encode($_POST['SqlArr']);


    //$SqlArr =json_decode($SqlArr);
    //$SqlArr=implode(',',$SqlArr);
    //$SqlArr=explode(',',$SqlArr);
    //$SqlArr=$SqlArr[0];

    //$myData3="Insert Into EmployeeTimesheets(EmpId, WkEnd, Day, Title, Description, Value,TimeStamp, AbbrevJob)  Values('$SqlArr[0][EmpId]','$SqlArr[0][WkEnd]','$SqlArr[0][Day]','$SqlArr[0][Title]','$SqlArr[0][Description]','$SqlArr[0][Value]', getDate(),'$SqlArr[0][AbbrevJob]')"; // this is my sql statment that is supposed to be inserting the data into the table.
    //$myData3="Insert Into EmployeeTimesheets  Values('$var1','$var2','$var3','$var4','$var5','$var6', getDate())";    
    //$myData3="Insert Into EmployeeTimesheets  Values('$EmpId','$WkEnd','$Day','$Title','$Description','$Value', getDate(),'$AbbrevJob')"; 

    //$record3 = odbc_exec($connect, $myData3);
    echo($SqlArr);

    odbc_close($connect);
    ?>
Desired results so the values can be inserted into SQL

Array ( [0] => 7 [1] => 09-19-2015 [2] => 09-13-2015 [3] => 1 [4] => 1 [5] => 7 [6]=>1 )
Array ( [0] => 7 [1] => 09-19-2015 [2] => 09-13-2015 [3] => 2 [4] => 2 [5] => 4 [6]=>2 )