简体   繁体   English

在表中循环以获取TD的结果

[英]Looping in table to get TDs' results

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? 我想遍历table tds以获取特定的单元格数据以将其插入数据库中,问题是当我将结果推到数组中时,它们彼此出现而不是分开的tds结果,我会错过吗?

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: 使用js对象将数据成对推送,该对象将在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: 的PHP:

foreach($_POST['data'] as $data) {
echo $data['OrderID'];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM