簡體   English   中英

在表中循環以獲取TD的結果

[英]Looping in table to get TDs' results

我想遍歷table tds以獲取特定的單元格數據以將其插入數據庫中,問題是當我將結果推到數組中時,它們彼此出現而不是分開的tds結果,我會錯過嗎?

結果

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 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");
  });
}

使用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:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM