0
如何從表格2中的某些值插入到表格1中。如果單擊了添加按鈕,我想要獲取所選行的所有值。我應該從我選擇的當前行獲得rowindex
,並通過rowindex
獲得$prod
值?從表格的選定行中獲取所有值
<table id="table1">
<tr>
<th>Product ID</th>
<th>Product Name</th>
<th>Price</th>
<th>Stock</th>
<th>Action</th>
</tr>
<?php foreach($prod->getAll() as $name):?>
<tr>
<td><?php echo $name['prod_id'];?></td>
<td><?php echo $name['name'];?></td>
<td><?php echo $name['price'];?></td>
<td><?php echo $name['stock'];?></td>
<td><button class="addbtn">Add</button></td>
</tr>
<?php endforeach;?>
</table>
<table id="table2">
<tr>
<th>No</th>
<th>Product Name</th>
<th>Price</th>
<th>Qty</th>
<th>Total</th>
</tr>
<tr>
<td>1</td>
<td>Some Product Name From Table 1</td>
<td>Some Product Price From Table 1</td>
<td>Qty is generated from table 1</td>
<td>Qty * Price</td>
</tr>
</table>
<?php
class Product extends DB_Connect
{
public function __construct()
{
parent::__construct();
}
function getAll(){
try
{
$sql = "SELECT * FROM product Order By prod_id asc";
$result = $this->db->query($sql);
$results = $result->fetchAll(PDO::FETCH_ASSOC);
return $results;
}
catch (Exception $e)
{
die ($e->getMessage());
}
}
}
?>