如何使用动态rowspan从< td>获取数据/值

voj3qocg  于 2021-06-17  发布在  Mysql
关注(0)|答案(0)|浏览(203)
<div class="container">
<form action="" method="post">
      <h4 class="title">REQUEST RESIN BASED ON PO CUSTOMER</h4>
<table>
  <tr>
    <th>Id</th>
    <th>Customer</th>
    <th>Month</th>
    <th>PO Number</th>
    <th>Part Number</th>
    <th>Part Name</th>
    <th>Qty Pcs</th>
    <th>Material Name</th>      
    <th>weight Product (Kg)</th>
    <th>Order Month</th>
    <th>Order Resin (Kg)</th>
    <th>Save Order</th>
  </tr>
<?php
$prevMonth = $prevPo = $prevDo = $prevKeyResin = "";
$rowspan=$total_kage=0;
    $results = $conn->query("SELECT PCAP.id,MP.part_number,MP.part_name,M.name,MR.resin,PCAP.qty,PC.po_number,MP.cavity,MP.weight_product,MP.weight_runner,PC.month 
                             ,CONCAT (MR.resin) AS KeyResin
                             ,CONCAT (DATE_FORMAT(PC.month,'%M %Y')) AS KeyMonth
                             ,CONCAT (PC.po_number) AS KeyPo
                             ,CONCAT (MR.resin) AS KeyName
                             FROM po_customer_add_product PCAP
                             LEFT JOIN po_customer PC ON PC.id=PCAP.po_customer_id 
                             LEFT JOIN master_product MP ON MP.id=PCAP.product_id 
                             LEFT JOIN master_resin MR ON MR.id=MP.material_name 
                             LEFT JOIN master M ON M.id=PCAP.customer 
                             Where PCAP.active='1' AND PCAP.open_po_resin='0' 
                             Order BY PC.month ASC,MR.resin ASC ");
// fetch pertama, utk cari jumlah rowspan dan Total(Kg)
$rowspan  = $rowname = $rowpo = $rowmon = $total_kage = 0;
$prevName = $prevPO = $prevMonth = $prevKeyResin = "";
$arrTotal = $arrRowSpan = array();
while($row = $results->fetch_array()) {
  $pcapid[] = $row['id'];
  $KeyName = $row['KeyName'];
  if($KeyName!=$prevName) { $prevName=$KeyName; $rowname=1; } else { $rowname++; }
  $arrRowSpan[$KeyName] = $rowname;
  $KeyMonth = $row['KeyMonth'];
  if($KeyMonth!=$prevMonth) { $prevMonth=$KeyMonth; $rowmon=1; } else { $rowmon++; }
  $arrRowSpan[$KeyMonth] = $rowmon;

  $KeyPo = $row['KeyPo'];
  if($KeyPo!=$prevPo) { $prevPo=$KeyPo; $rowpo=1; } else { $rowpo++; }
  $arrRowSpan[$KeyPo] = $rowpo;

  $KeyResin = $row['KeyResin'];
  $hasilshot = $row['qty']/$row['cavity'];
  $weight1shot = ($row['weight_product']*$row['cavity'])+($row['weight_runner']);
  $weighttotal = ($weight1shot*$hasilshot)/1000;
  if($KeyResin != $prevKeyResin) {
    $prevKeyResin = $KeyResin;
    $total_kage = $weighttotal;
    $rowspan = 1;
  } else {
    $total_kage += $weighttotal;
    $rowspan++;
  }  
  $arrTotal[$KeyResin] = array( 'rowspan' => $rowspan, 'total_kage' => $total_kage );
}

$prevName = $prevPo = $prevMonth = $prevKeyResin = "";
$results->data_seek(0);  // balikin lagi ke row[0]
while($row = $results->fetch_array()) {
  $Name = $row['resin'];
  $PO = $row['po_number'];
  $Month = date('F Y',strtotime($row['month']));
  $KeyName = $row['KeyName'];
  $KeyMonth = $row['KeyMonth'];
  $KeyResin = $row['KeyResin'];
  $KeyPo = $row['KeyPo'];

  $hasilshot = $row['qty']/$row['cavity'];
  $weight1shot = ($row['weight_product']*$row['cavity'])+($row['weight_runner']);
  $weighttotal = ($weight1shot*$hasilshot)/1000;

  $td_name = $td_month = $td_po = $ttl_kg = $ttl_kg1 = $ttl_kg2 = $ttl_kg3  = "";
  if($KeyName!=$prevName) {
    $prevName = $KeyName; $rowspan = $arrRowSpan[$KeyName];
    $td_name = "<td rowspan='$rowspan'  class='td-name'>$Name</td>";
  }
  if($KeyMonth!=$prevMonth) {
    $prevMonth = $KeyMonth; $rowspan = $arrRowSpan[$KeyMonth];
    $td_month = "<td rowspan='$rowspan'  class='td-month'>$Month</td>";
  }

  if($KeyPo!=$prevPo) {
    $prevPo = $KeyPo; $rowspan = $arrRowSpan[$KeyPo];
    $td_po = "<td rowspan='$rowspan'>$PO</td>";
  }

  if($KeyResin != $prevKeyResin) {
     $mulai = new DateTime($row['month']);
     $mulai->add(new DateInterval('P1M'));      
     $sampe = new DateTime('+7 month');
     $interval = new DateInterval('P1M');
     $rangetgl = new DatePeriod($mulai, $interval ,$sampe);
$option = "";
  foreach($rangetgl as $tgl){
    $dateid = $tgl->format("Y-m");
    $dateoption = $tgl->format("F Y");
    $option .= "<option value='$dateid'>$dateoption</option>";
  };     
    $prevKeyResin = $KeyResin;
    $rowspan = $arrTotal[$KeyResin]['rowspan'];
    $total_kage = $arrTotal[$KeyResin]['total_kage'];
    $ttl_kg = "<td rowspan='$rowspan'  class='td-weighttotal'>$total_kage</td>";
    $ttl_kg1 = "<td rowspan='$rowspan'  class='td-poorderresin'>
    <select name='pomonth' class='select-field9'  required>
    <option value='0'>Choose Month</option>
    $option 
    </select>
    </td>
    ";
    $ttl_kg2 = "<td rowspan='$rowspan'>
    <input type='text' required class='input-field9' autocomplete='off' name='qtyorder' onkeypress='return onlyNumbers(event);' maxlength='6' onkeyup='oneDot(this)'/>
    <input type='hidden' name='unique' value='mrp_order_resin' readonly='readonly' required />
    </td>
    ";
    $ttl_kg3 = "<td rowspan='$rowspan'><button class='btnSelect'>Order</button>
    ";
  }
  ?>
<?php
echo "<tr>
      <td class='td-id'>".$row['id']."</td>
      <td class='td-customer'>".$row['name']."</td>
      $td_month 
      <td class='td-po'>".$row['po_number']."</td>
      <td class='td-partnumber'>".$row['part_number']."</td>
      <td class='td-partname'>".$row['part_name']."</td>
      <td class='td-qtypcs'>".$row['qty']."</td>
      $td_name
      $ttl_kg
      $ttl_kg1
      $ttl_kg2
      $ttl_kg3
      </tr>";  
} 
?>  
</table>
<div class="clearfix">
</div>
<div class="mid-popular">
</div>
</form>
</div>
<script>
//*
$(document).ready(function(){

    $(".btnSelect").on('click',function(){
  // get the current row
  var currentRow = $(this).closest("tr");

  var col1 = currentRow.find(".td-id").html(); 
  var col2 = currentRow.find(".td-customer").html(); 
  var col3 = currentRow.find(".td-month").html(); 
  var col4 = currentRow.find(".td-po").html(); 
  var col5 = currentRow.find(".td-partnumber").html(); 
  var col6 = currentRow.find(".td-partname").html(); 
  var col7 = currentRow.find(".td-qtypcs").html(); 
  var col8 = currentRow.find(".td-name").html(); 
  var col9 = currentRow.find(".td-weighttotal").html(); 
  var col10 = currentRow.find(":selected").html(); 
  var col11 = currentRow.find("input[name='qtyorder']").html(); 

  var data = col1 + "\n" + col2 + "\n" + col3 + "\n" + col4 + "\n" + col5 + "\n" + col6 + "\n" + col7 + "\n" + col8 + "\n" + col9 + "\n" + col10 + "\n" + col11;

  alert(data);
});
});
//*
</script>

结果浏览器
现在只显示1个id和订单树脂(kg)
此代码没有使用连接到数据库

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<style>
table {width:100%;}
th {background-color: #4CAF50;color: white;}
table, th, td {border: 1px solid black;border-collapse: collapse;}
th, td {padding: 15px;text-align: left;}
table#t01 tr:nth-child(even) {background-color: #eee;}
table#t01 tr:nth-child(odd) {background-color: #fff;}
table#t01 th { background-color: black;color: white;}
.btnSelect {
    background-color: #f44336;
    border: 2px solid #f44336;
    border-radius: 4px;
    color: white;
    cursor: pointer;
}

.btnSelect:hover{
 background-color: #c93326;    border: 2px solid #c93326;

}
</style>
<div class="container">
<form action="" method="post">
      <h4 class="title">REQUEST RESIN BASED ON PO CUSTOMER</h4>
<table>
  <tr>
    <th>Id</th>
    <th>Customer</th>
    <th>Month</th>
    <th>PO Number</th>
    <th>Part Number</th>
    <th>Part Name</th>
    <th>Qty Pcs</th>
    <th>Material Name</th>      
    <th>weight Product (Kg)</th>
    <th>Order Month</th>
    <th>Order Resin (Kg)</th>
    <th>Save Order</th>
  </tr>
<tr>
      <td class='td-id'>99</td>
      <td class='td-customer'>ASMO</td>
      <td rowspan='7'  class='td-month'>December 2018</td> 
      <td class='td-po'>ASMO1</td>
      <td class='td-partnumber'>ASMO-4-4</td>
      <td class='td-partname'>ASMO4</td>
      <td class='td-qtypcs'>1002</td>
      <td rowspan='3'  class='td-name'>DELRIN 111 PA (NC)</td>
      <td rowspan='3'  class='td-weighttotal'>74.511</td>
      <td rowspan='3'  class='td-poorderresin'>
    <select name='pomonth' class='select-field9'  required>
    <option value='0'>Choose Month</option>
    <option value='2019-01'>January 2019</option><option value='2019-02'>February 2019</option><option value='2019-03'>March 2019</option><option value='2019-04'>April 2019</option><option value='2019-05'>May 2019</option><option value='2019-06'>June 2019</option>    
    </select>
    </td>

      <td rowspan='3'>
    <input type='text' required class='input-field9' autocomplete='off' name='qtyorder' onkeypress='return onlyNumbers(event);' maxlength='6' onkeyup='oneDot(this)'/>
    <input type='hidden' name='unique' value='mrp_order_resin' readonly='readonly' required />
    </td>

      <td rowspan='3'><button class='btnSelect'>Order</button>

      </tr><tr>
      <td class='td-id'>101</td>
      <td class='td-customer'>YAMAHA</td>

      <td class='td-po'>YAMAHA1</td>
      <td class='td-partnumber'>Y1</td>
      <td class='td-partname'>YAMAHA1</td>
      <td class='td-qtypcs'>2000</td>

      </tr><tr>
      <td class='td-id'>103</td>
      <td class='td-customer'>DENSO</td>

      <td class='td-po'>DENSO1</td>
      <td class='td-partnumber'>D1</td>
      <td class='td-partname'>D1-11</td>
      <td class='td-qtypcs'>3000</td>

      </tr><tr>
      <td class='td-id'>98</td>
      <td class='td-customer'>ASMO</td>

      <td class='td-po'>ASMO1</td>
      <td class='td-partnumber'>ASMO-3-3</td>
      <td class='td-partname'>ASMO3</td>
      <td class='td-qtypcs'>1001</td>
      <td rowspan='2'  class='td-name'>DURACON M90-44 (NC)</td>
      <td rowspan='2'  class='td-weighttotal'>7.25425</td>
      <td rowspan='2'  class='td-poorderresin'>
    <select name='pomonth' class='select-field9'  required>
    <option value='0'>Choose Month</option>
    <option value='2019-01'>January 2019</option><option value='2019-02'>February 2019</option><option value='2019-03'>March 2019</option><option value='2019-04'>April 2019</option><option value='2019-05'>May 2019</option><option value='2019-06'>June 2019</option>    
    </select>
    </td>

      <td rowspan='2'>
    <input type='text' required class='input-field9' autocomplete='off' name='qtyorder' onkeypress='return onlyNumbers(event);' maxlength='6' onkeyup='oneDot(this)'/>
    <input type='hidden' name='unique' value='mrp_order_resin' readonly='readonly' required />
    </td>

      <td rowspan='2'><button class='btnSelect'>Order</button>

      </tr><tr>
      <td class='td-id'>97</td>
      <td class='td-customer'>ASMO</td>

      <td class='td-po'>ASMO1</td>
      <td class='td-partnumber'>ASMO-2-2</td>
      <td class='td-partname'>ASMO2</td>
      <td class='td-qtypcs'>1000</td>

      </tr><tr>
      <td class='td-id'>100</td>
      <td class='td-customer'>ASMO</td>

      <td class='td-po'>ASMO1</td>
      <td class='td-partnumber'>ASMO-5-5</td>
      <td class='td-partname'>ASMO5</td>
      <td class='td-qtypcs'>1003</td>
      <td rowspan='1'  class='td-name'>IUPILON S 3000 R (BK)</td>
      <td rowspan='1'  class='td-weighttotal'>28.209375</td>
      <td rowspan='1'  class='td-poorderresin'>
    <select name='pomonth' class='select-field9'  required>
    <option value='0'>Choose Month</option>
    <option value='2019-01'>January 2019</option><option value='2019-02'>February 2019</option><option value='2019-03'>March 2019</option><option value='2019-04'>April 2019</option><option value='2019-05'>May 2019</option><option value='2019-06'>June 2019</option>    
    </select>
    </td>

      <td rowspan='1'>
    <input type='text' required class='input-field9' autocomplete='off' name='qtyorder' onkeypress='return onlyNumbers(event);' maxlength='6' onkeyup='oneDot(this)'/>
    <input type='hidden' name='unique' value='mrp_order_resin' readonly='readonly' required />
    </td>

      <td rowspan='1'><button class='btnSelect'>Order</button>

      </tr><tr>
      <td class='td-id'>102</td>
      <td class='td-customer'>YAMAHA</td>

      <td class='td-po'>YAMAHA1</td>
      <td class='td-partnumber'>Y2</td>
      <td class='td-partname'>YAMAHA2</td>
      <td class='td-qtypcs'>2000</td>
      <td rowspan='1'  class='td-name'>LLDPE F-410 (NC)</td>
      <td rowspan='1'  class='td-weighttotal'>32.5</td>
      <td rowspan='1'  class='td-poorderresin'>
    <select name='pomonth' class='select-field9'  required>
    <option value='0'>Choose Month</option>
    <option value='2019-01'>January 2019</option><option value='2019-02'>February 2019</option><option value='2019-03'>March 2019</option><option value='2019-04'>April 2019</option><option value='2019-05'>May 2019</option><option value='2019-06'>June 2019</option>    
    </select>
    </td>

      <td rowspan='1'>
    <input type='text' required class='input-field9' autocomplete='off' name='qtyorder' onkeypress='return onlyNumbers(event);' maxlength='6' onkeyup='oneDot(this)'/>
    <input type='hidden' name='unique' value='mrp_order_resin' readonly='readonly' required />
    </td>

      <td rowspan='1'><button class='btnSelect'>Order</button>

      </tr>  
</table>
<div class="clearfix">
</div>
<div class="mid-popular">
</div>
</form>
</div>
<script>
//*
$(document).ready(function(){

    $(".btnSelect").on('click',function(){
  // get the current row
  var currentRow = $(this).closest("tr");

  var col1 = currentRow.find(".td-id").html(); 
  var col2 = currentRow.find(".td-customer").html(); 
  var col3 = currentRow.find(".td-month").html(); 
  var col4 = currentRow.find(".td-po").html(); 
  var col5 = currentRow.find(".td-partnumber").html(); 
  var col6 = currentRow.find(".td-partname").html(); 
  var col7 = currentRow.find(".td-qtypcs").html(); 
  var col8 = currentRow.find(".td-name").html(); 
  var col9 = currentRow.find(".td-weighttotal").html(); 
  var col10 = currentRow.find(":selected").html(); 
  var col11 = currentRow.find("input[name='qtyorder']").html(); 

  var data = col1 + "\n" + col2 + "\n" + col3 + "\n" + col4 + "\n" + col5 + "\n" + col6 + "\n" + col7 + "\n" + col8 + "\n" + col9 + "\n" + col10 + "\n" + col11;

  alert(data);
});
});
//*
</script>

如何利用动态行跨度从“td”中获取价值?
已经试过了,但运气不好。已经阅读了jquery-get value of标记,它的rowspan不止一个如何获取表row td的值,它有一个row span列,但是没有相同的case可以帮助我

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题