这是我的表名 tbl_quotation_items:
qou_id | rfq_no | quo_desc | quo_supp | quo_total_cost |
---|---|---|---|---|
1 | 23-0003 | 键盘和鼠标 | 阿本森 | 6000 |
2 | 23-0003 | P.E 管 3/4 | 阿本森 | 11050 |
3 | 23-0003 | 键盘和鼠标 | 艾森贸易 | 5400 |
4 | 23-0003 | P.E 管 3/4 | 艾森贸易 | 12070 |
我期待在 HTML 表中有这样的输出:
rfq_no | quo_desc | 阿本森 | 阿尔森交易 |
---|---|---|---|
23-0003 | 键盘和鼠标 | 6000 | 5400 |
23-0003 | P.E 管 3/4 | 11050 | 12070 |
我的代码只是从这个堆栈:
$query = "SELECT * FROM tbl_quotation_items WHERE rfq_no ='".$_POST['rfq_no']."'";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$count = $statement->rowCount();
$output .= '
<table class="table">
<thead>
<TR>
<TH>Article/Description</TH>
</TR>
<thead>';
if($count > 0)
{
foreach($result as $row)
{
$output .= '
<tr>
<TD class="text-secondary" width="30%">
'.$row["rfq_desc"].'
</TD>
</tr>';
}
}
$output .='</table>';
echo $output;
$connect = null;
请帮忙!谢谢
你能试试下面的代码吗
<?php
// Establish a connection to the database
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_database_name";
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check if the connection is successful
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// Fetch the records from the database
$sql = "SELECT * FROM tbl_quotation_items WHERE rfq_no = '23-0003'";
$result = mysqli_query($conn, $sql);
// Display the records in an HTML table
echo "<table>";
echo "<tr><th>rfq_no</th><th>quo_desc</th><th>Abenson</th><th>Alson Trading</th></tr>";
while ($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>" . $row["rfq_no"] . "</td>";
echo "<td>" . $row["quo_desc"] . "</td>";
echo "<td>" . $row["Abenson"] . "</td>";
echo "<td>" . $row["Alson Trading"] . "</td>";
echo "</tr>";
}
echo "</table>";
// Close the database connection
mysqli_close($conn);
?>
如果您遇到任何问题,请告诉我