我设计了一个html输出表,它进入我的数据库以从中挑选出值,我还在其他表中包含提交按钮,供用户从值数组中进行选择,这是sql表
这是我用来输出表格的代码
<table class="table table-hover mails m-0 table table-actions-bar">
<thead>
<tr>
<th>Level</th>
<th>Amount</th>
<th>Potential Earning</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
for ($i = 0; $i < count($levels); $i++) {
$level = $levels[$i];
?>
<tr>
<td>
<?php echo ($level->getLevel()); ?>
</td>
<td>
<?php echo ($level->getAmount()); ?>
</td>
<td>
<?php echo ($level->getPotentialEarning()); ?>
</td>
<td>
<button type="submit" value="Add Project" style="background-color:steelblue; color:white">Add Project</button>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
但是,我遇到的唯一问题是添加项目按钮如何将实际金额提交到用户数据库,请帮忙
最佳答案
只需解析按钮附加链接的金额即可。如果您决定不使用表单,此方法将会起作用。如果您决定使用表单,只需添加一个名为 amount 的隐藏输入字段并解析其中的值
<table class="table table-hover mails m-0 table table-actions-bar">
<thead>
<tr>
<th>Level</th>
<th>Amount</th>
<th>Potential Earning</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
for ($i = 0; $i < count($levels); $i++) {
$level = $levels[$i];
?>
<tr>
<td>
<?php echo ($level->getLevel()); ?>
</td>
<td>
<?php echo ($level->getAmount()); ?>
</td>
<td>
<?php echo ($level->getPotentialEarning()); ?>
</td>
<td>
<a type="submit" href="script.php?amount=<?php echo ($level->getAmount()); ?>" class="btn btn-default" value="Add Project" style="background-color:steelblue; color:white">Add Project</button>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
在您的 php 保存中,您可以检查为:
if(isset($_GET['amount']) && is_numeric($_GET['amount'])){
$amount = $_GET['amount'];
}
关于javascript - 如何将数组的值输入到我的数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43345129/