我正在尝试在同一客户的发票上回显多个项目。我可以从数据库中回显它们,但是不是每个项目都在同一张发票上(在不同的行上)回显,它会将完整的发票与每个项目回应2次(或更多,具体取决于发票上的项目数量)在每张发票上。下面是我的代码(我还没有清理代码。一旦代码工作,我将离开那一步。)
<?php include "database_connection.php" ?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>DPB quote</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex, nofollow">
<link rel="stylesheet" href="css/bootstrap.min.css"><!--erase this link once the app is completed-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel='stylesheet' type='text/css' href='css/style2.css' />
<link rel='stylesheet' type='text/css' href='css/print.css' media="print" />
<script type='text/javascript' src='js/jquery-1.3.2.min.js'></script>
<script type='text/javascript' src='js/example.js'></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.dataTables.min.js"></script>
<script src="js/dataTables.bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css"><!--search pagination and delete reference link-->
<script type="text/javascript" src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script><!--search pagination and delete reference link-->
</head>
<body>
<?php
$statement = $connect->prepare("
SELECT * FROM tbl_order
WHERE order_id = :order_id
LIMIT 1
");
$statement->execute(
array(
':order_id' => $_GET["id"]
)
);
$result = $statement->fetchAll();
foreach($result as $row)
{
?>
<script>
$(document).ready(function(){
$('#order_no').val("<?php echo $row["order_no"]; ?>");
$('#order_date').val("<?php echo $row["order_date"]; ?>");
$('#order_receiver_name').val("<?php echo $row["order_receiver_name"]; ?>");
$('#address_line_1').val("<?php echo $row["address_line_1"]; ?>");
$('#address_line_2').val("<?php echo $row["address_line_2"]; ?>");
$('#city').val("<?php echo $row["city"]; ?>");
$('#state').val("<?php echo $row["state"]; ?>");
$('#zip_code').val("<?php echo $row["zip_code"]; ?>");
$('#phone_number').val("<?php echo $row["phone_number"]; ?>");
$('#email').val("<?php echo $row["email"]; ?>");
$('#notes').val("<?php echo $row["notes"]; ?>");
});
</script>
<form method="post" id="invoice_form">
<div class="container">
<?php
$statement = $connect->prepare("
SELECT * FROM tbl_order_item
WHERE order_id = :order_id
");
$statement->execute(
array(
':order_id' => $_GET["id"]
)
);
$item_result = $statement->fetchAll();
$m = 0;
foreach($item_result as $sub_row)
{
$m = $m + 1;
?>
<!--QUOTATION APP 2 STARTS HERE-->
<div id="page-wrap">
<textarea id="header">Quotation</textarea>
<div id="identity">
<textarea id="address">Discount Plastic Bags
7750
Suite
Irving
Phone: </textarea>
<div id="logo">
<div id="logohelp">
(max width: 540px, max height: 300px)
</div>
<img id="image" src="images/dpblogo3.png" alt="logo" />
</div>
</div>
<div style="clear:both"></div>
<div id="customer">
<!--<form id="quote_date" class="" action="index.php" method="post">-->
<tr>
<td><textarea placeholder="Enter Customer Information" id="address" name="company_info"></textarea></td>
</tr>
<table id="meta">
<tr>
<td class="meta-head">Invoice #</td>
<td><textarea>000123</textarea></td>
</tr>
<tr>
<td class="meta-head">Date</td>
<td><textarea placeholder="enter quotation date" name="quote_date"></textarea></td>
</tr>
<tr>
<td class="meta-head">Amount Due</td>
<td><textarea placeholder="enter amount due" name="amount_due"></textarea></td>
</tr>
</table>
</div>
<table id="items">
<tr>
<th>SKU</th>
<th>Description</th>
<th>Quantity</th>
<th>Unit Cost</th>
<th>Price</th>
</tr>
<tr class="item-row">
<!--<td><span id="sr_no"><?php //echo $m; ?></span></td>-->
<td><input type="text" name="sku[]" id="sku<?php echo $m; ?>" class="item-name" value="<?php echo $sub_row["sku"]; ?>" /></td>
<td><input type="text" name="item_name[]" id="item_name<?php echo $m; ?>" class="description" value="<?php echo $sub_row["item_name"]; ?>" /></td>
<td><input type="text" name="order_item_quantity[]" id="order_item_quantity<?php echo $m; ?>" data-srno="<?php echo $m; ?>" class="qty" value = "<?php echo $sub_row["order_item_quantity"]; ?>" /></td>
<td><input type="text" name="order_item_price[]" id="order_item_price<?php echo $m; ?>" data-srno="<?php echo $m; ?>" class="cost" value="<?php echo $sub_row["order_item_price"]; ?>" /></td>
<td><input type="text" name="order_item_final_amount[]" id="order_item_final_amount<?php echo $m; ?>" data-srno="<?php echo $m; ?>" readonly class="price" value="<?php echo $sub_row["order_item_final_amount"]; ?>" /></td>
</tr>
<tr>
<td colspan="2" class="blank"></td>
<td colspan="2" class="total-line">Subtotal</td>
<td class="total-value"><textarea id="subtotal" name="subtotal"></textarea></td>
</tr>
<tr>
<td colspan="2" class="blank"></td>
<td colspan="2" class="total-line">Total</td>
<td class="total-value"><textarea name="total" id="total"></textarea></td>
</tr>
<tr>
<td colspan="2" class="blank"> </td>
<td colspan="2" class="total-line">Amount Paid</td>
<td class="total-value"><textarea id="paid">$0.00</textarea></td>
</tr>
<tr>
<td colspan="2" class="blank"> </td>
<td colspan="2" class="total-line balance">Balance Due</td>
<td class="total-value balance"><textarea name="balance_due" class="due"> </textarea></td>
</tr>
</table>
<div id="terms">
<h5>Notes</h5>
<textarea name="notes" placeholder="enter quotation notes" rows="12" style="font-size: 15pt"></textarea>
</div>
</div>
</form>
</body>
</html>
<?php
}
}
?>
答案 0 :(得分:0)
我会做这样的事情。这不是测试,只是我如何做的一个例子。还有其他一些方法,但这最适合我
// other needed code above
$results = sqlsrv_query($link, $query);
//query returns one value for these
echo "<table>";
echo "<tr> ";
echo "<td>".$name."</td>";
echo "<td>".$store."</td>";
echo "</tr>";
//start your multiple items row
while($row=sqlsrv_fetch_array($results))
{
$items = $row['items'];
echo "<tr> ";
echo "<td>".$items."</td> ";
echo "</tr>";
}
echo "<tr> ";
echo "<td>".$cost."</td>";
echo "<td>".$other."</td>";
echo "</tr>";
echo "</table> ";
//other code for the rest of the page below
结果将是:
Bob Bob's Store
ITEM
ITEM
ITEM
$50.00 other