0
我有一個循環中重複行的代碼,但是如何在while循環中重複整個表格。 代碼是如何在while循環中重複整個表格
$kandivli = mysql_query("SELECT ps_order_detail.product_name, sum(ps_order_detail.product_quantity) AS product_total FROM ps_order_detail JOIN ps_product ON ps_product.id_product = ps_order_detail.product_id JOIN ps_orders ON ps_orders.id_order = ps_order_detail.id_order WHERE ps_product.id_supplier = '" . $supplier_number . "' && ps_orders.current_state = '" . $status1 ."' && ps_order_detail.id_shop = 1 GROUP BY ps_order_detail.product_name");
$ktotal = mysql_query("SELECT sum(ps_order_detail.product_quantity) AS product_total FROM ps_order_detail JOIN ps_product ON ps_product.id_product = ps_order_detail.product_id JOIN ps_orders ON ps_orders.id_order = ps_order_detail.id_order WHERE ps_product.id_supplier = '" . $supplier_number . "' && ps_orders.current_state = '" . $status1 ."' && ps_order_detail.id_shop = 1");
$krow = mysql_fetch_array($ktotal);
$kftotal = $krow['product_total'];
if(mysql_num_rows($kandivli) > 0)
{
echo '<table border="1" align="center" class="total">';
echo "<th> Product Name </td><th> Total Quantity </th>";
while($kandivlirow = mysql_fetch_array($kandivli))
{
$kandivli_product = $kandivlirow['product_name'];
$kandivlitotal = $kandivlirow['product_total'];
echo '<tr>';
echo "<td align='center'>$kandivli_product</td><tdalign='center'>$kandivlitotal</td>";
echo '</tr>';
}
echo "<td align='center'><b>Total</b></td><td align='center'><b>$kftotal</b></td>";
echo '</table>';
}
else echo "<div align='center'>No Pending orders</div>";
?>
現在,我只是有5間店鋪,但如果我每次添加一個新的店我不得不復制粘貼這個代碼更改爲& & ps_order_detail.id_shop = 6然後& & ps_order_detail.id_shop = 7等
所以,如果有人如何顯示如何重複表。這將是感激。 希望我的問題很明確。 (我要重複整個表) 問候
阿莫德
好,我已編輯的代碼現在我得到預期6張桌子,但行顯示一個店的相同的數據。
<?php
session_start();
include_once "connect.php";
?>
<?php
$supplier = mysql_query("SELECT ps_order_detail.product_name, sum(ps_order_detail.product_quantity) AS product_total, ps_supplier.name FROM ps_order_detail JOIN ps_product ON ps_product.id_product = ps_order_detail.product_id JOIN ps_supplier ON ps_supplier.id_supplier = ps_product.id_supplier JOIN ps_orders ON ps_orders.id_order = ps_order_detail.id_order WHERE ps_orders.current_state = 4 GROUP BY ps_order_detail.id_shop");
$alltotal = mysql_query("SELECT sum(ps_order_detail.product_quantity) AS producttotal FROM ps_order_detail JOIN ps_product ON ps_product.id_product = ps_order_detail.product_id JOIN ps_orders ON ps_orders.id_order = ps_order_detail.id_order WHERE ps_orders.current_state = 4 && ps_order_detail.id_shop = 11");
$ct = mysql_fetch_array($alltotal);
$ct1 = $ct['producttotal'];
while($supplierrow = mysql_fetch_array($supplier))
{
$kandivli = mysql_query("SELECT ps_order_detail.product_name, sum(ps_order_detail.product_quantity) AS product_total,ps_supplier.name FROM ps_order_detail JOIN ps_product ON ps_product.id_product = ps_order_detail.product_id JOIN ps_supplier ON ps_supplier.id_supplier = ps_product.id_supplier JOIN ps_orders ON ps_orders.id_order = ps_order_detail.id_order WHERE ps_orders.current_state = 4 GROUP BY ps_order_detail.product_name");
echo '<table border="1" align="center" class="total">';
while($kandivlirow = mysql_fetch_array($kandivli))
{
$sup = $kandivlirow['name'];
$sp = $kandivlirow['product_name'];
$spt = $kadivlirow['product_total'];
echo '<tr>';
echo "<td align='center'>$sp</td><td align='center'>$spt</td><td align='center'>$sup</td>";
echo '</tr>';
}
echo '</table>';
echo '<br>';
}
echo "<td align='center'><b>Total</b></td><td align='center'><b>$ct1</b></td>";
?>