php循环嵌套的问题
<?mysql_select_db($database_cnn,$cnn);mysql_query("setnames'gbk'");//这就是指定数据库字符集$offi...
<?
mysql_select_db($database_cnn, $cnn);
mysql_query("set names 'gbk'");//这就是指定数据库字符集
$officesql = "Select bm,name FROM Office order by id ";
$officequery = mysql_query($officesql,$cnn);
$a = mysql_query("select bm,name from food order by bm",$cnn);
while($office = mysql_fetch_array($officequery)){
echo $office['name'];
while($ars = mysql_fetch_array($a)){
$sql ="select sum(foodorder.foodnum) from foodorder,member where foodorder.user=member.user and member.office = '".$office['bm']."' and foodorder.foodbm = '".$ars['bm']."'";
$query = mysql_query($sql,$cnn);
$c =mysql_fetch_array($query);
echo $ars['bm']."| ".$c[0];
}
echo "<br>";
}
?>
显示的结果如下:
嘉华大厦A座TC0001| TC0002| TC0003| TC0004| TC0005|
嘉华大厦B座
嘉华大厦C座
嘉华大厦D座
嘉华大厦E座
嘉华大厦F座
中关村E世界
为什么外循环起作用,而内循环只显示一行! 展开
mysql_select_db($database_cnn, $cnn);
mysql_query("set names 'gbk'");//这就是指定数据库字符集
$officesql = "Select bm,name FROM Office order by id ";
$officequery = mysql_query($officesql,$cnn);
$a = mysql_query("select bm,name from food order by bm",$cnn);
while($office = mysql_fetch_array($officequery)){
echo $office['name'];
while($ars = mysql_fetch_array($a)){
$sql ="select sum(foodorder.foodnum) from foodorder,member where foodorder.user=member.user and member.office = '".$office['bm']."' and foodorder.foodbm = '".$ars['bm']."'";
$query = mysql_query($sql,$cnn);
$c =mysql_fetch_array($query);
echo $ars['bm']."| ".$c[0];
}
echo "<br>";
}
?>
显示的结果如下:
嘉华大厦A座TC0001| TC0002| TC0003| TC0004| TC0005|
嘉华大厦B座
嘉华大厦C座
嘉华大厦D座
嘉华大厦E座
嘉华大厦F座
中关村E世界
为什么外循环起作用,而内循环只显示一行! 展开
1个回答
展开全部
<?
mysql_select_db($database_cnn, $cnn);
mysql_query("set names 'gbk'");//这就是指定数据库字符集
$officesql = "Select bm,name FROM Office order by id ";
$officequery = mysql_query($officesql,$cnn);
//$a = mysql_query("select bm,name from food order by bm",$cnn);
while($office = mysql_fetch_array($officequery)){
echo $office['name'];
//
$a = mysql_query("select bm,name from food order by bm",$cnn);
//
while($ars = mysql_fetch_array($a)){
$sql ="select sum(foodorder.foodnum) from foodorder,member where foodorder.user=member.user and member.office = '".$office['bm']."' and foodorder.foodbm = '".$ars['bm']."'";
$query = mysql_query($sql,$cnn);
$c =mysql_fetch_array($query);
echo $ars['bm']."| ".$c[0];
}
echo "<br>";
}
mysql_select_db($database_cnn, $cnn);
mysql_query("set names 'gbk'");//这就是指定数据库字符集
$officesql = "Select bm,name FROM Office order by id ";
$officequery = mysql_query($officesql,$cnn);
//$a = mysql_query("select bm,name from food order by bm",$cnn);
while($office = mysql_fetch_array($officequery)){
echo $office['name'];
//
$a = mysql_query("select bm,name from food order by bm",$cnn);
//
while($ars = mysql_fetch_array($a)){
$sql ="select sum(foodorder.foodnum) from foodorder,member where foodorder.user=member.user and member.office = '".$office['bm']."' and foodorder.foodbm = '".$ars['bm']."'";
$query = mysql_query($sql,$cnn);
$c =mysql_fetch_array($query);
echo $ars['bm']."| ".$c[0];
}
echo "<br>";
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询