我在获取某些单元格的apprpriate值时遇到问题....在第一页中我得到了相应的结果..但在下一页中,产品信息,总价格和订单利润的值所有值都为0,但所有其他字段都包含正确的信息。
每页显示五条记录..代码如下:
<?include"dbconnect.php"?>
session_start();
?>
<?include "adminhead.php"?>
<?include "adminleftnav.php"?>
<div id="seasonal">
<table width="635" border="0" align="left" bgcolor="#CCCCCC" >
<tr>
<td>
<table width="635" border="0" align="left" >
<tr>
<td width="52" bgcolor="#E0EBED">Order Number</td>
<td width="150" bgcolor="#E0EBED">Product Information</td>
<td width="100" bgcolor="#E0EBED">Total Price(TK)</td>
<td width="90" bgcolor="#E0EBED">Order Date</td>
<td width="80" bgcolor="#E0EBED">Payment Status</td>
<td width="100" bgcolor="#E0EBED">Profit from order(TK)</td>
</tr>
</table>
</td>
</tr>
<?php
if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
$start_from = ($page-1)*5 ;
$sql = "Select distinct order_no,date,payment_status from product_order_info order by order_no ASC LIMIT $start_from,5";
$query_for_order1 = mysql_query ($sql);
?>
<tr>
<td>
<table id="foo" border="1" bgcolor="#f4eddb" cellspacing="2" cellborder="2" width=635>
<? while($row_for_my_order1=mysql_fetch_assoc($query_for_order1))
{
?>
<tr>
<td width=52>
<?echo $row_for_my_order1['order_no'];?>
</td>
<td width=156>
<?
$sql1 = "Select * from product_order_info where order_no= '$row_for_my_order1[order_no]' order by order_no ASC LIMIT $start_from,5";
$query_for_order = mysql_query($sql1);
while($row_for_my_order=mysql_fetch_assoc($query_for_order))
{
$query_for_product_details=mysql_query("select * from product where product_no='$row_for_my_order[product_id]' ");
$row_for_product_details=mysql_fetch_array($query_for_product_details);
?>
<br>
<?echo $row_for_product_details['product_name'];
?>
<br>
Quantity
<?echo $row_for_my_order['quantity'];
}
?>
</td>
<td width=106>
<?
$total=0;
$sql1 = "Select * from product_order_info where order_no= '$row_for_my_order1[order_no]' order by order_no ASC LIMIT $start_from,5";
$query_for_order = mysql_query($sql1);
while($row_for_my_order2=mysql_fetch_assoc($query_for_order))
{
$query_for_product_details=mysql_query("select * from product where product_no='$row_for_my_order2[product_id]' ");
$row_for_product_details=mysql_fetch_array($query_for_product_details);
$total = $total+ $row_for_product_details['sell_price'] * $row_for_my_order2['quantity'];
}
echo $total;
?>
</td>
<td width=90>
<?echo $row_for_my_order1['date'];?>
</td>
<td>
<?echo $row_for_my_order1['payment_status'];?>
</td>
<td width=100>
<? $total=0;
$sql1 = "Select * from product_order_info where order_no= '$row_for_my_order1[order_no]' order by order_no ASC LIMIT $start_from,5";
$query_for_order = mysql_query($sql1);
while($row_for_my_order3=mysql_fetch_assoc($query_for_order))
{
$total=$total+$row_for_my_order3['profit'];
}
echo $total; ?>
</td>
</tr>
<?
}
?>
</table>
</div>
<?php
$sql = "SELECT DISTINCT COUNT(order_no) FROM product_order_info";
$rs_result = mysql_query($sql);
$row = mysql_fetch_row($rs_result);
$total_records = $row[0];
$total_pages = ceil($total_records / 5);
for ($i=1; $i<=$total_pages; $i++) {
echo "<a href='view_order.php?page=".$i."'>".$i."</a> ";
};
?>
<?include "footer1.php"?>
请帮助我......
答案 0 :(得分:0)
除了第一个查询之外,您应该从每个查询中删除LIMIT $start_from,5
。正如Dagon指出的那样,您应该考虑使用单个查询的可能性,以减少对SQL服务器的查询次数。