php网页,表格显示不了数据?(在线等)

来源:百度知道 编辑:UC知道 时间:2024/06/15 16:57:47
代码如下:
if( $amount )
{
$sql = "select * from store order by store_id desc limit ". ($page-1)*$page_size .", $page_size";
$result = mysql_query($sql);
$num = mysql_num_rows($result);
echo "当前页面有".$num."记录<br>";
echo "<table border=3 width=58% align=center bordercolor=#3399FF><th>产品名称</th><th>产品现存数量</th><th>提示</th><th>备注</th>";
for ($i=0;$i<$num;$i++)
{
$rs=mysql_fetch_object($result);
$id=$rs->store_id;
$name = $rs->store_name;
$price=$rs->store_price;
$now=$rs->store_now;
$total = $rs->store_total;
$remark=$rs->store_remark;
if ($now>0 && $now<3) {
echo "<tr><td>".$name."</t

把你下面的这一段:
for ($i=0;$i<$num;$i++)
{
.......
}

修改为:
while($rs=mysql_fetch_object($result))
{
$id=$rs->store_id;
$name = $rs->store_name;
$price=$rs->store_price;
$now=$rs->store_now;
$total = $rs->store_total;
$remark=$rs->store_remark;
$note='';
if ($now>0 && $now<3) $note='该产品库存不足,请即时进货';
else if($now>4) $note='该产品库存充足';
echo "<tr><td>$name</td><td>$now</td><td bgcolor=red>$note</td><td>无不良情况</td></tr>";
}
mysql_free_result($result);

一楼说的是一方面的问题,但不至于导致每页都没有数据。

我看了下的你的代码,明显就有问题。

首先:$rs=mysql_fetch_object($result)这句不应该写在for循环里面

其次:$i+=0 好像没有实际的意义

还有:$now 等于0,3,4的情况你都没有包括进去

检查一下, $rs=mysql_fetch_object($result);
有没有取得对象

if($now>4)改成else

可能是你下一