I want to loop through table
tds to get specific cells data to insert them on a database, the problem is that when I push the results to an array they appear with each other not separate tds results, do I miss something?
Results
Array
(
[0] => 8
[1] => 3
[2] => 22
[3] => All quantity finally confirmed
[4] => 8
[5] => 2
[6] => 9
[7] => Not all quantity finally confirmed
)
Function
function UpdateResults()
{
var table = $('#SearchResults');
var OrderID;
var CatID;
var ProID;
var Status;
var data = [];
table.find('tbody tr').each(function()
{
OrderID = $(this).find("td").eq(0).html();
CatID = $(this).find("td").eq(3).html();
ProID = $(this).find("td").eq(4).html();
Status = $(this).find("td:eq(6) select").val();
data.push(OrderID,CatID,ProID,Status);
});
jsonString = JSON.stringify(data);
$.ajax({
type:"POST",
url : 'UpdateResults.php',
data : {'Data':jsonString}
}).done(function(response) {
alert ("Done");
});
}
Push the data as pairs using a js object that will be converted to a associative array in php:
table.find('tbody tr').each(function()
{
OrderID = $(this).find("td").eq(0).html();
CatID = $(this).find("td").eq(3).html();
ProID = $(this).find("td").eq(4).html();
Status = $(this).find("td:eq(6) select").val();
data.push({OrderID:OrderID,CatID:CatID,ProID:ProID,Status:Status});
});
php:
foreach($_POST['data'] as $data) {
echo $data['OrderID'];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.