1){ $orderbydesc=""; $descTXT="↓"; }else{ $orderbydesc=" desc"; $descTXT="↑"; } If ($orderby=="") { $orderby="OA_DepartmentID,OA_User_ID"; $descTXT="↓"; } //查询开始 $SqlOrdDateType=empty($SqlOrdDateType)!=false ? "" : $SqlOrdDateType; $OrdClassType=empty($OrdClassType)!=false ? "1" : $OrdClassType; $sql="select UserID,UserName,UserPhone, PointsSpent=(select isnull(sum(Points_Score),0) from UserPoints where Points_State=1 and ToUserID=UserID and Points_Score<0 and Points_Time ".$SqlOrdDateType."), PointsIncome=(select isnull(sum(Points_Score),0) from UserPoints where Points_State=1 and ToUserID=UserID and Points_Score>0 and Points_Time ".$SqlOrdDateType.") from UserData where UserID in (select ToUserID from UserPoints where Points_State=1 and Points_Time ".$SqlOrdDateType.")"; //echo $sql;exit; $data = sqlsrv_query($conn,$sql); if($data == true){ $FormArray=array(); //表头 $FormArray[0]=array("序号","客户手机","积分支出汇总","积分收入汇总","积分累计"); $FormArrayX=count($FormArray[0]); if (sqlsrv_rows_affected($data)==0) { $SystemMessageType=2; $SystemMessageTXT="数据库中相关无数据!"; $y=0; } else { $y=0; $i=0; while($rs = sqlsrv_fetch_array( $data, SQLSRV_FETCH_ASSOC) ) { //读取数据 $UserID = $rs['UserID']; $UserPhone = $rs['UserPhone']; $PointsSpent = intval($rs['PointsSpent']); $PointsIncome = intval($rs['PointsIncome']); //读取数据--End //写入数组 $i++; $FormArray[$i][0]=$i; $FormArray[$i][1]="$UserPhone"; $FormArray[$i][2]=$PointsSpent; $FormArray[$i][3]=$PointsIncome; $FormArray[$i][4]=$PointsIncome+$PointsSpent; //写入数组--End } } } //echo print_r($FormArray); //exit; ?>