首頁 >後端開發 >php教程 >while嵌套while只输出一次?

while嵌套while只输出一次?

WBOY
WBOY原創
2016-06-23 13:52:041434瀏覽

			$startDate = '2014-07-28';						$endDate   = $startDate ;						$nowDate =Date('Y-m-d',time());						$days=round((time()-strtotime("$startDate"))/86400);						while($endDate != $nowDate){				while($row=mssql_fetch_array($result)){										$result1=mssql_query("select sum(JE) from VW_SDLSMX where DM1='$row[KHDM]' and RQ='$endDate'",$conn);										while($rowlist1=mssql_fetch_array($result1)){												$rowlist1[RiQi]="$endDate";												$rowlist1[KHMC]=$row[KHMC];												$rowlist[1][]=$rowlist1;											}									}				    			$endDate = date('Y-m-d',strtotime($endDate.' +1 day'));    						}
 while嵌套while只输出一次?菜鸟求帮助,谢谢


回复讨论(解决方案)

你这个报错不

你有三重 while 是哪一重不对?
打印出相关变量看看

你这个报错不

 谢谢回复,不报错。
$rowlist
array(1) { [1]=> array(20) { [0]=> array(4) { [0]=> string(8) "164.0000" ["computed"]=> string(8) "164.0000" ["RiQi"]=> string(10) "2014-07-28" ["KHMC"]=> string(12) "南京中央" } [1]=> array(4) { [0]=> string(9) "4512.0000" ["computed"]=> string(9) "4512.0000" ["RiQi"]=> string(10) "2014-07-28" ["KHMC"]=> string(12) "南京商厦" } [2]=> array(4) { [0]=> string(9) "1207.0000" ["computed"]=> string(9) "1207.0000" ["RiQi"]=> string(10) "2014-07-28" ["KHMC"]=> string(12) "南京山百" } [3]=> array(4) { [0]=> string(9) "2985.0000" ["computed"]=> string(9) "2985.0000" ["RiQi"]=> string(10) "2014-07-28" ["KHMC"]=> string(12) "南京湖百" } [4]=> array(4) { [0]=> string(9) "5327.0000" ["computed"]=> string(9) "5327.0000" ["RiQi"]=> string(10) "2014-07-28" ["KHMC"]=> string(12) "南京太平" } [5]=> array(4) { [0]=> string(9) "1360.0000" ["computed"]=> string(9) "1360.0000" ["RiQi"]=> string(10) "2014-07-28" ["KHMC"]=> string(12) "南京九龙" } [6]=> array(4) { [0]=> string(8) "700.0000" ["computed"]=> string(8) "700.0000" ["RiQi"]=> string(10) "2014-07-28" ["KHMC"]=> string(12) "南京长发" } [7]=> array(4) { [0]=> string(9) "4152.0000" ["computed"]=> string(9) "4152.0000" ["RiQi"]=> string(10) "2014-07-28" ["KHMC"]=> string(15) "南京新城市" } [8]=> array(4) { [0]=> string(9) "2633.0000" ["computed"]=> string(9) "2633.0000" ["RiQi"]=> string(10) "2014-07-28" ["KHMC"]=> string(15) "湖南路专卖" } [9]=> array(4) { [0]=> string(10) "10672.0000" ["computed"]=> string(10) "10672.0000" ["RiQi"]=> string(10) "2014-07-28" ["KHMC"]=> string(12) "江宁苏果" } [10]=> array(4) { [0]=> string(9) "2323.0000" ["computed"]=> string(9) "2323.0000" ["RiQi"]=> string(10) "2014-07-28" ["KHMC"]=> string(12) "溧水苏果" } [11]=> array(4) { [0]=> string(8) "750.0000" ["computed"]=> string(8) "750.0000" ["RiQi"]=> string(10) "2014-07-28" ["KHMC"]=> string(15) "瑞金路特惠" } [12]=> array(4) { [0]=> string(9) "1194.0000" ["computed"]=> string(9) "1194.0000" ["RiQi"]=> string(10) "2014-07-28" ["KHMC"]=> string(12) "桥北华联" } [13]=> array(4) { [0]=> string(9) "1530.0000" ["computed"]=> string(9) "1530.0000" ["RiQi"]=> string(10) "2014-07-28" ["KHMC"]=> string(12) "六合苏果" } [14]=> array(4) { [0]=> string(9) "1540.0000" ["computed"]=> string(9) "1540.0000" ["RiQi"]=> string(10) "2014-07-28" ["KHMC"]=> string(15) "三牌楼特惠" } [15]=> array(4) { [0]=> string(9) "8629.0000" ["computed"]=> string(9) "8629.0000" ["RiQi"]=> string(10) "2014-07-28" ["KHMC"]=> string(12) "南京新百" } [16]=> array(4) { [0]=> string(9) "1399.0000" ["computed"]=> string(9) "1399.0000" ["RiQi"]=> string(10) "2014-07-28" ["KHMC"]=> string(12) "南京德基" } [17]=> array(4) { [0]=> string(9) "1218.0000" ["computed"]=> string(9) "1218.0000" ["RiQi"]=> string(10) "2014-07-28" ["KHMC"]=> string(15) "江宁万尚城" } [18]=> array(4) { [0]=> string(9) "2772.0000" ["computed"]=> string(9) "2772.0000" ["RiQi"]=> string(10) "2014-07-28" ["KHMC"]=> string(15) "瑞金路专卖" } [19]=> array(4) { [0]=> NULL ["computed"]=> NULL ["RiQi"]=> string(10) "2014-07-28" ["KHMC"]=> string(18) "江宁富腾奥莱" } } }

你有三重 while 是哪一重不对?
打印出相关变量看看

谢谢回复,最里层的只循环了一次。
打印$rowlist结果如下:
array(1) {  [1]=>  array(20) {    [0]=>    array(4) {      [0]=>      string(8) "164.0000"      ["computed"]=>      string(8) "164.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京中央"    }    [1]=>    array(4) {      [0]=>      string(9) "4512.0000"      ["computed"]=>      string(9) "4512.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京商厦"    }    [2]=>    array(4) {      [0]=>      string(9) "1207.0000"      ["computed"]=>      string(9) "1207.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京山百"    }    [3]=>    array(4) {      [0]=>      string(9) "2985.0000"      ["computed"]=>      string(9) "2985.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京湖百"    }    [4]=>    array(4) {      [0]=>      string(9) "5327.0000"      ["computed"]=>      string(9) "5327.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京太平"    }    [5]=>    array(4) {      [0]=>      string(9) "1360.0000"      ["computed"]=>      string(9) "1360.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京九龙"    }    [6]=>    array(4) {      [0]=>      string(8) "700.0000"      ["computed"]=>      string(8) "700.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京长发"    }    [7]=>    array(4) {      [0]=>      string(9) "4152.0000"      ["computed"]=>      string(9) "4152.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(15) "南京新城市"    }    [8]=>    array(4) {      [0]=>      string(9) "2633.0000"      ["computed"]=>      string(9) "2633.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(15) "湖南路专卖"    }    [9]=>    array(4) {      [0]=>      string(10) "10672.0000"      ["computed"]=>      string(10) "10672.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "江宁苏果"    }    [10]=>    array(4) {      [0]=>      string(9) "2323.0000"      ["computed"]=>      string(9) "2323.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "溧水苏果"    }    [11]=>    array(4) {      [0]=>      string(8) "750.0000"      ["computed"]=>      string(8) "750.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(15) "瑞金路特惠"    }    [12]=>    array(4) {      [0]=>      string(9) "1194.0000"      ["computed"]=>      string(9) "1194.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "桥北华联"    }    [13]=>    array(4) {      [0]=>      string(9) "1530.0000"      ["computed"]=>      string(9) "1530.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "六合苏果"    }    [14]=>    array(4) {      [0]=>      string(9) "1540.0000"      ["computed"]=>      string(9) "1540.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(15) "三牌楼特惠"    }    [15]=>    array(4) {      [0]=>      string(9) "8629.0000"      ["computed"]=>      string(9) "8629.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京新百"    }    [16]=>    array(4) {      [0]=>      string(9) "1399.0000"      ["computed"]=>      string(9) "1399.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京德基"    }    [17]=>    array(4) {      [0]=>      string(9) "1218.0000"      ["computed"]=>      string(9) "1218.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(15) "江宁万尚城"    }    [18]=>    array(4) {      [0]=>      string(9) "2772.0000"      ["computed"]=>      string(9) "2772.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(15) "瑞金路专卖"    }    [19]=>    array(4) {      [0]=>      NULL      ["computed"]=>      NULL      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(18) "江宁富腾奥莱"    }  }}	

最里层的依赖第二层的查询结果: DM1='$row[KHDM]' and RQ='$endDate'
你怎么就知道一定会有?

最里层的依赖第二层的查询结果: DM1='$row[KHDM]' and RQ='$endDate'
你怎么就知道一定会有?


我加了一个输出
$startDate = '2014-07-28';						$endDate   = $startDate ;						$nowDate =Date('Y-m-d',time());						$days=round((time()-strtotime("$startDate"))/86400);						while($endDate != $nowDate){				while($row=mssql_fetch_array($result)){										$result1=mssql_query("select sum(JE) from VW_SDLSMX where DM1='$row[KHDM]' and RQ='$endDate'",$conn);					echo $endDate;										while($rowlist1=mssql_fetch_array($result1)){												$rowlist1[RiQi]="$endDate";												$rowlist1[KHMC]=$row[KHMC];												$rowlist[1][]=$rowlist1;											}									}				    			$endDate = date('Y-m-d',strtotime($endDate.' +1 day'));    						}

结果都为2014-07-28,第二层就只循环了一次。

那不就说明 $result 只有一条记录吗?

那不就说明 $result 只有一条记录吗?

 额。。。第二个嵌套加个break
$startDate = '2014-07-28';						$endDate   = $startDate ;						$nowDate =Date('Y-m-d',time());						$days=round((time()-strtotime("$startDate"))/86400);						while($endDate != $nowDate){				while($row=mssql_fetch_array($result)){										$result1=mssql_query("select sum(JE) from VW_SDLSMX where DM1='$row[KHDM]' and RQ='$endDate'",$conn);										while($rowlist1=mssql_fetch_array($result1)){												$rowlist1[RiQi]="$endDate";												$rowlist1[KHMC]=$row[KHMC];												$rowlist[1][]=$rowlist1;											}					break;				}				    			$endDate = date('Y-m-d',strtotime($endDate.' +1 day'));    						}

结果就这样了
array(1) {  [1]=>  array(11) {    [0]=>    array(4) {      [0]=>      string(8) "164.0000"      ["computed"]=>      string(8) "164.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京中央"    }    [1]=>    array(4) {      [0]=>      string(9) "3181.0000"      ["computed"]=>      string(9) "3181.0000"      ["RiQi"]=>      string(10) "2014-07-29"      ["KHMC"]=>      string(12) "南京商厦"    }    [2]=>    array(4) {      [0]=>      string(9) "3435.0000"      ["computed"]=>      string(9) "3435.0000"      ["RiQi"]=>      string(10) "2014-07-30"      ["KHMC"]=>      string(12) "南京山百"    }    [3]=>    array(4) {      [0]=>      string(9) "3174.0000"      ["computed"]=>      string(9) "3174.0000"      ["RiQi"]=>      string(10) "2014-07-31"      ["KHMC"]=>      string(12) "南京湖百"    }    [4]=>    array(4) {      [0]=>      string(9) "5207.0000"      ["computed"]=>      string(9) "5207.0000"      ["RiQi"]=>      string(10) "2014-08-01"      ["KHMC"]=>      string(12) "南京太平"    }    [5]=>    array(4) {      [0]=>      string(9) "2620.0000"      ["computed"]=>      string(9) "2620.0000"      ["RiQi"]=>      string(10) "2014-08-02"      ["KHMC"]=>      string(12) "南京九龙"    }    [6]=>    array(4) {      [0]=>      string(9) "3667.0000"      ["computed"]=>      string(9) "3667.0000"      ["RiQi"]=>      string(10) "2014-08-03"      ["KHMC"]=>      string(12) "南京长发"    }    [7]=>    array(4) {      [0]=>      string(9) "2344.0000"      ["computed"]=>      string(9) "2344.0000"      ["RiQi"]=>      string(10) "2014-08-04"      ["KHMC"]=>      string(15) "南京新城市"    }    [8]=>    array(4) {      [0]=>      string(9) "2082.0000"      ["computed"]=>      string(9) "2082.0000"      ["RiQi"]=>      string(10) "2014-08-05"      ["KHMC"]=>      string(15) "湖南路专卖"    }    [9]=>    array(4) {      [0]=>      string(9) "7988.0000"      ["computed"]=>      string(9) "7988.0000"      ["RiQi"]=>      string(10) "2014-08-06"      ["KHMC"]=>      string(12) "江宁苏果"    }    [10]=>    array(4) {      [0]=>      string(8) "958.0000"      ["computed"]=>      string(8) "958.0000"      ["RiQi"]=>      string(10) "2014-08-07"      ["KHMC"]=>      string(12) "溧水苏果"    }  }}	

7月28到8月7号都是有内容的,但是就只循环一次

echo mssql_num_rows($result);
加载 while($row=mssql_fetch_array($result)){ 前面

真不知道是你写程序,还是程序写你

$startDate = '2014-07-28';						$endDate   = $startDate ;						$nowDate =Date('Y-m-d',time());						$days=round((time()-strtotime("$startDate"))/86400);						while($endDate != $nowDate){			echo mssql_num_rows($result);				while($row=mssql_fetch_array($result)){										$result1=mssql_query("select sum(JE) from VW_SDLSMX where DM1='$row[KHDM]' and RQ='$endDate'",$conn);										while($rowlist1=mssql_fetch_array($result1)){												$rowlist1[RiQi]="$endDate";												$rowlist1[KHMC]=$row[KHMC];												$rowlist[1][]=$rowlist1;											}				}				    			$endDate = date('Y-m-d',strtotime($endDate.' +1 day'));    						}


我被程序上了

输出的结果是

num  都是对的,应该不会只循环了一次,楼主是怎么知道只循环了一次的?

 while($endDate != $nowDate){     echo mssql_num_rows($result); //看看这里     while($row=mssql_fetch_array($result)){          $result1=mssql_query("select sum(JE) from VW_SDLSMX where DM1='$row[KHDM]' and RQ='$endDate'",$conn);          echo mssql_num_rows($result1); //再看看这里


你有三重 while 是哪一重不对?
打印出相关变量看看

谢谢回复,最里层的只循环了一次。
打印$rowlist结果如下:
array(1) {  [1]=>  array(20) {    [0]=>    array(4) {      [0]=>      string(8) "164.0000"      ["computed"]=>      string(8) "164.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京中央"    }    [1]=>    array(4) {      [0]=>      string(9) "4512.0000"      ["computed"]=>      string(9) "4512.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京商厦"    }    [2]=>    array(4) {      [0]=>      string(9) "1207.0000"      ["computed"]=>      string(9) "1207.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京山百"    }    [3]=>    array(4) {      [0]=>      string(9) "2985.0000"      ["computed"]=>      string(9) "2985.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京湖百"    }    [4]=>    array(4) {      [0]=>      string(9) "5327.0000"      ["computed"]=>      string(9) "5327.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京太平"    }    [5]=>    array(4) {      [0]=>      string(9) "1360.0000"      ["computed"]=>      string(9) "1360.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京九龙"    }    [6]=>    array(4) {      [0]=>      string(8) "700.0000"      ["computed"]=>      string(8) "700.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京长发"    }    [7]=>    array(4) {      [0]=>      string(9) "4152.0000"      ["computed"]=>      string(9) "4152.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(15) "南京新城市"    }    [8]=>    array(4) {      [0]=>      string(9) "2633.0000"      ["computed"]=>      string(9) "2633.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(15) "湖南路专卖"    }    [9]=>    array(4) {      [0]=>      string(10) "10672.0000"      ["computed"]=>      string(10) "10672.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "江宁苏果"    }    [10]=>    array(4) {      [0]=>      string(9) "2323.0000"      ["computed"]=>      string(9) "2323.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "溧水苏果"    }    [11]=>    array(4) {      [0]=>      string(8) "750.0000"      ["computed"]=>      string(8) "750.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(15) "瑞金路特惠"    }    [12]=>    array(4) {      [0]=>      string(9) "1194.0000"      ["computed"]=>      string(9) "1194.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "桥北华联"    }    [13]=>    array(4) {      [0]=>      string(9) "1530.0000"      ["computed"]=>      string(9) "1530.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "六合苏果"    }    [14]=>    array(4) {      [0]=>      string(9) "1540.0000"      ["computed"]=>      string(9) "1540.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(15) "三牌楼特惠"    }    [15]=>    array(4) {      [0]=>      string(9) "8629.0000"      ["computed"]=>      string(9) "8629.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京新百"    }    [16]=>    array(4) {      [0]=>      string(9) "1399.0000"      ["computed"]=>      string(9) "1399.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京德基"    }    [17]=>    array(4) {      [0]=>      string(9) "1218.0000"      ["computed"]=>      string(9) "1218.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(15) "江宁万尚城"    }    [18]=>    array(4) {      [0]=>      string(9) "2772.0000"      ["computed"]=>      string(9) "2772.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(15) "瑞金路专卖"    }    [19]=>    array(4) {      [0]=>      NULL      ["computed"]=>      NULL      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(18) "江宁富腾奥莱"    }  }}	

看这个:
$rowlist[1][]=$rowlist1;
你都堆到$rowlist[1]里了,所以你觉得只进行了一次。。。。。

3重while。。。难道不能联合查询去掉一层?跑起来不小心就是3次方啊



你有三重 while 是哪一重不对?
打印出相关变量看看

谢谢回复,最里层的只循环了一次。
打印$rowlist结果如下:
array(1) {  [1]=>  array(20) {    [0]=>    array(4) {      [0]=>      string(8) "164.0000"      ["computed"]=>      string(8) "164.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京中央"    }    [1]=>    array(4) {      [0]=>      string(9) "4512.0000"      ["computed"]=>      string(9) "4512.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京商厦"    }    [2]=>    array(4) {      [0]=>      string(9) "1207.0000"      ["computed"]=>      string(9) "1207.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京山百"    }    [3]=>    array(4) {      [0]=>      string(9) "2985.0000"      ["computed"]=>      string(9) "2985.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京湖百"    }    [4]=>    array(4) {      [0]=>      string(9) "5327.0000"      ["computed"]=>      string(9) "5327.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京太平"    }    [5]=>    array(4) {      [0]=>      string(9) "1360.0000"      ["computed"]=>      string(9) "1360.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京九龙"    }    [6]=>    array(4) {      [0]=>      string(8) "700.0000"      ["computed"]=>      string(8) "700.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京长发"    }    [7]=>    array(4) {      [0]=>      string(9) "4152.0000"      ["computed"]=>      string(9) "4152.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(15) "南京新城市"    }    [8]=>    array(4) {      [0]=>      string(9) "2633.0000"      ["computed"]=>      string(9) "2633.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(15) "湖南路专卖"    }    [9]=>    array(4) {      [0]=>      string(10) "10672.0000"      ["computed"]=>      string(10) "10672.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "江宁苏果"    }    [10]=>    array(4) {      [0]=>      string(9) "2323.0000"      ["computed"]=>      string(9) "2323.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "溧水苏果"    }    [11]=>    array(4) {      [0]=>      string(8) "750.0000"      ["computed"]=>      string(8) "750.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(15) "瑞金路特惠"    }    [12]=>    array(4) {      [0]=>      string(9) "1194.0000"      ["computed"]=>      string(9) "1194.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "桥北华联"    }    [13]=>    array(4) {      [0]=>      string(9) "1530.0000"      ["computed"]=>      string(9) "1530.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "六合苏果"    }    [14]=>    array(4) {      [0]=>      string(9) "1540.0000"      ["computed"]=>      string(9) "1540.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(15) "三牌楼特惠"    }    [15]=>    array(4) {      [0]=>      string(9) "8629.0000"      ["computed"]=>      string(9) "8629.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京新百"    }    [16]=>    array(4) {      [0]=>      string(9) "1399.0000"      ["computed"]=>      string(9) "1399.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(12) "南京德基"    }    [17]=>    array(4) {      [0]=>      string(9) "1218.0000"      ["computed"]=>      string(9) "1218.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(15) "江宁万尚城"    }    [18]=>    array(4) {      [0]=>      string(9) "2772.0000"      ["computed"]=>      string(9) "2772.0000"      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(15) "瑞金路专卖"    }    [19]=>    array(4) {      [0]=>      NULL      ["computed"]=>      NULL      ["RiQi"]=>      string(10) "2014-07-28"      ["KHMC"]=>      string(18) "江宁富腾奥莱"    }  }}	

看这个:
$rowlist[1][]=$rowlist1;
你都堆到$rowlist[1]里了,所以你觉得只进行了一次。。。。。    如果都堆到1里的话  那结果应该是最后一天的,而不是第一天的吧

你按我#14的建议做了吗?
看看结果好吗

不知道你外层的查询语句是什么样的
通常只要不是树状数据,只要关联查询就可解决问题
少了一重循环,就少了一半的出错几率

你按我#14的建议做了吗?
看看结果好吗

不知道你外层的查询语句是什么样的
通常只要不是树状数据,只要关联查询就可解决问题
少了一重循环,就少了一半的出错几率


我只建议你 2 处 echo, 后面的 11个  20 是哪里来的?
也不想想:为什么 20条记录在内层只出 11 个 20

也不断一下行,连续的数字,你知道谁对谁吗?
20 应表示外层有 20 条记录
20 个 1 表示每条记录对应有一条记录($result1=mssql_query("select sum(JE) from VW_SDLSMX where DM1='$row[KHDM]' and RQ='$endDate'",$conn);)
所以最终结果应有 20 个元素,你#4打印的不正好是 20 个吗?

我只建议你 2 处 echo, 后面的 11个  20 是哪里来的?
也不想想:为什么 20条记录在内层只出 11 个 20

也不断一下行,连续的数字,你知道谁对谁吗?
20 应表示外层有 20 条记录
20 个 1 表示每条记录对应有一条记录($result1=mssql_query("select sum(JE) from VW_SDLSMX where DM1='$row[KHDM]' and RQ='$endDate'",$conn);)
所以最终结果应有 20 个元素,你#4打印的不正好是 20 个吗?



$startDate = '2014-07-28';						$endDate   = $startDate ;						$nowDate =Date('Y-m-d',time());						$days=round((time()-strtotime("$startDate"))/86400);						while($endDate != $nowDate){			echo mssql_num_rows($result);			echo '<br>';				while($row=mssql_fetch_array($result)){					$result1=mssql_query("select sum(JE) from VW_SDLSMX where DM1='$row[KHDM]' and RQ='$endDate'",$conn);					echo mssql_num_rows($result1); 					echo '<br>';					while($rowlist1=mssql_fetch_array($result1)){												$rowlist1[RiQi]="$endDate";												$rowlist1[KHMC]=$row[KHMC];											$rowlist[1][]=$rowlist1;											}				}				    			$endDate = date('Y-m-d',strtotime($endDate.' +1 day'));    						}


明白了,后面的 20 是 while($endDate != $nowDate) 循环输出的
其实你的代码本身并没有多大问题,只是忽略了这样一个事实:
while($row=mssql_fetch_array($result)) 将读空结果集 $result
再次进入就没得读了,所以你需要回绕结果集 mssql_field_seek

mssql_field_seek($result, 0);while($row=mssql_fetch_array($result)) {


我只建议你 2 处 echo, 后面的 11个  20 是哪里来的?
也不想想:为什么 20条记录在内层只出 11 个 20

也不断一下行,连续的数字,你知道谁对谁吗?
20 应表示外层有 20 条记录
20 个 1 表示每条记录对应有一条记录($result1=mssql_query("select sum(JE) from VW_SDLSMX where DM1='$row[KHDM]' and RQ='$endDate'",$conn);)
所以最终结果应有 20 个元素,你#4打印的不正好是 20 个吗?


$startDate = '2014-07-28';						$endDate   = $startDate ;						$nowDate =Date('Y-m-d',time());						$days=round((time()-strtotime("$startDate"))/86400);						while($endDate != $nowDate){			echo mssql_num_rows($result);			echo '.';				while($row=mssql_fetch_array($result)){					$result1=mssql_query("select sum(JE) from VW_SDLSMX where DM1='$row[KHDM]' and RQ='$endDate'",$conn);					echo mssql_num_rows($result1); 					echo '-';					while($rowlist1=mssql_fetch_array($result1)){												$rowlist1[RiQi]="$endDate";												$rowlist1[KHMC]=$row[KHMC];											$rowlist[1][]=$rowlist1;											}				}				    			$endDate = date('Y-m-d',strtotime($endDate.' +1 day'));    						}


怎么又弄错了:{
代码的第9行改为

mssql_data_seek($result, 0);while($row=mssql_fetch_array($result)) {
不是
mssql_field_seek($result, 0);
while($row=mssql_fetch_array($result)) {

怎么又弄错了:{
代码的第9行改为

mssql_data_seek($result, 0);while($row=mssql_fetch_array($result)) {
不是
mssql_field_seek($result, 0);
while($row=mssql_fetch_array($result)) {



谢谢!
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn