php - 如何使用相同的发票编号调用 Mysql 表中每列的不同值?
问题描述
我有一个表purchase_details
,其中一些值具有相同的invoice_no
. 现在我需要每个数据都相同,并将它们输出到一个长度invoice_no
相同的输入字段中。invoice_no
由于我是 PHP 新手,我尝试使用数组,但它显示了最后一行的字母。
<table align="center" style="width:800px;">
<thead>
<tr>
<th>#</th>
<th style="text-align:center;">Item Name</th>
<th style="text-align:center;">Total Quantity</th>
<th style="text-align:center;">Quantity</th>
<th style="text-align:center;">Buy Price</th>
<th>Total</th>
</tr>
</thead>
<tbody id="invoice_item">
<?php
$query1="select * from purchase_details where invoice_no=$id";
$query1_run=mysqli_query($connect , $query1);
while($row=mysqli_fetch_array($query1_run)){
$product_name = $row['product_name'];
}
echo $product_name[0];
?>
<tr>
<td><b id="number"></b></td>
<td>
<select name="pid[]" class="form-control form-control-sm" required>
<option selected=""></option>
</select>
</td>
<td><input name="tqty[]" readonly type="text" class="form-control form-control-sm" ></td>
<td><input name="qty[]" type="text" class="form-control form-control-sm" required value=""></td>
<td><input name="price[]" type="text" class="form-control form-control-sm" readonly value=""></td>
<td></td>
</tr>
</tbody>
</table>
解决方案
您应该在表数据之后结束 while 循环
<table align="center" style="width:800px;">
<thead>
<tr>
<th>#</th>
<th style="text-align:center;">Item Name</th>
<th style="text-align:center;">Total Quantity</th>
<th style="text-align:center;">Quantity</th>
<th style="text-align:center;">Buy Price</th>
<th>Total</th>
</tr>
</thead>
<tbody id="invoice_item">
<?php
$query1="select * from purchase_details where invoice_no=$id";
$query1_run=mysqli_query($connect , $query1);
while($row=mysqli_fetch_array($query1_run)){
$product_name = $row['product_name'];
echo $product_name[0];
?>
<tr>
<td><b id="number"></b></td>
<td>
<select name="pid[]" class="form-control form-control-sm" required>
<option selected=""></option>
</select>
</td>
<td><input name="tqty[]" readonly type="text" class="form-control form-control-sm" ></td>
<td><input name="qty[]" type="text" class="form-control form-control-sm" required value=""></td>
<td><input name="price[]" type="text" class="form-control form-control-sm" readonly value=""></td>
<td></td>
</tr>
<?php } ?>
</tbody>
</table>
推荐阅读
- mysql - 导致 MySQL 最大密钥长度超出的 Spring 数据
- node.js - 如何在 Angular 2 中应用 LDAP?
- java - 无法使用 jcifs 连接到 unc 位置
- sql - 如何为显示的 azure cosmos db 文档编写 SQL 查询?
- presto - 如何查看 Presto UI 中使用的每个子查询内存
- html - 模糊背景引导程序
- java - 在 ITelephony 实现期间对错误接口的 Binder 调用
- windows-phone-8 - 识别商店应用类型
- java - 从肥皂网络服务获得响应为零
- angular - ngx-imageviewer MissingPDFException