因此,我处于自动取款机上,并且被要求从SQL表中检索信息并将其显示为发票,但是我掌握了基础知识,但是现在我被要求格式化php页面以使其看起来像这样的东西
我对如何执行此操作甚至从何处开始感到困惑。如果您可以就如何开始格式化这样的页面为我指明正确的方向,那很好,我在下面留下了我的代码,任何帮助将不胜感激
require("connect.php");
$inNo = $_POST["inNo"];
$sql = "SELECT invoice.invoice_no, invoice.date, invoice.cust_id, invoice.emp_id, invoice_line.prod_id, invoice_line.qty, product.cost_price, (product.cost_price * invoice_line.qty) FROM invoice INNER JOIN invoice_line ON invoice.invoice_no = invoice_line.invoice_no INNER JOIN product ON invoice_line.prod_id = product.id WHERE cust_id = '" . $inNo . "'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
//open table
echo '<table class="table table-striped" id="outTable">';
echo "<tr><th>Invoice no.</th><th>Date</th><th>Customer ID</th><th>Employee ID</th><th>Product ID</th><th>Qty</th><th>Price</th><th>Total cost</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "
<tr>
<td>" . $row["invoice_no"]. "</td>
<td>" . $row["date"]. "</td><td>" . $row["cust_id"]. "</td>
<td>" . $row["emp_id"]. "</td><td>" . $row["prod_id"]. "</td>
<td>" . $row["qty"]. "</td><td>" . $row["cost_price"]. "</td>
<td>" . $row["(product.cost_price * invoice_line.qty)"]. "</td>
</tr>";
}
} else {
echo "0 results";
}
$conn->close();
?>
PHP的 SQL 格式
分享改善这个问题
2小时前 问
帐篷人8001
311枚青铜徽章
这个问题是关于html / css而不是关于php / sql。请在代码段中向我们显示生成的html,并说明它与您想要的内容有何不同 – Denis Sheremet 1小时前
添加评论
1个回答
活跃的最古老的选票
0
尝试这个:
<?php
require("connect.php");
$inNo = $_POST["inNo"];
$sql = "SELECT invoice.invoice_no, invoice.date, invoice.cust_id, invoice.emp_id, invoice_line.prod_id, invoice_line.qty, product.cost_price, (product.cost_price * invoice_line.qty) FROM invoice INNER JOIN invoice_line ON invoice.invoice_no = invoice_line.invoice_no INNER JOIN product ON invoice_line.prod_id = product.id WHERE cust_id = '" . $inNo . "'";
$result = $conn->query($sql);
echo"<div style='width:50em'>";
if ($result->num_rows > 0) {
$count =0;
while($row = $result->fetch_assoc()) {
if ($count==0){
echo '<h2 style="text-align: center">Invoice no. " . $row["invoice_no"]. "</h2>';
echo '<table width=100%>';
echo "<tr style='text-align: left'><th>Date</th><th>Customer ID</th><th>Employee ID</th></tr>";
echo '<td>" . $row["date"]. "</td><td>" . $row["cust_id"]. "</td>
<td>" . $row["emp_id"]. "</td></table>';
echo '<table class="table table-striped" id="outTable" width=100% style="text-align: left">';
echo '<th>Product ID</th><th>Qty</th><th>Price</th></tr>';
}
echo "
<tr>
<td>" . $row["prod_id"]. "</td>
<td>" . $row["qty"]. "</td><td>" . $row["cost_price"]. "</td>
</tr>";
if ($count==$result->num_rows-1){
echo '<div style="text-align: right">Total cost: " . $row["(product.cost_price * invoice_line.qty)"]. "</div>';
}
$count++;
}
echo "</table></div>";
} else {
echo "0 results";
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。