Reputation: 43
I have a table named purchase_details
with some values which has the same invoice_no
. Now I need each of the data with the same invoice_no
and output them in a input field which will the same amount of the invoice_no
length.
As i am new to PHP I have tried to use an array but it's showing the letters of the last row.
<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>
Upvotes: 0
Views: 28
Reputation: 26
You should end the while loop after the table data
<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>
Upvotes: 1