<?phprequire('config.inc.php');date_default_timezone_set("Asia/Shanghai");header("Content-type: text/html; charset=utf-8");$str_from=$_GET["from"].' 00:00:00';$str_to=$_GET["to"].' 00:00:00';$from_time=strtotime($str_from);$to_time=strtotime($str_to);$display_all=array_key_exists("dispall",$_POST);if($from_time>=$to_time){echo'起始时间必须小于截止时间';return;}$conn=mysqli_connect($_CFG['mysql_host'],$_CFG['mysql_user'],$_CFG['mysql_pwd'],$_CFG['mysql_db']);if(mysqli_connect_errno($conn)){echo"mysql连接失败!".mysqli_connect_error();return;}$result=mysqli_query($conn,"SELECT COUNT(1) FROM user_statis WHERE first_time >= $from_time AND first_time < $to_time");$row=mysqli_fetch_row($result);$total=$row[0];if($display_all){$strsql="SELECT first_appid as AppId, (SELECT COUNT(1) FROM user_statis WHERE first_time >= $from_time AND first_time < $to_time AND first_appid = AppId) AS Number FROM user_statis GROUP BY first_appid ORDER BY Number DESC";}else{$strsql="SELECT first_appid as AppId, (SELECT COUNT(1) FROM user_statis WHERE first_time >= $from_time AND first_time < $to_time AND first_appid = AppId) AS Number FROM user_statis WHERE first_time >= $from_time AND first_time < $to_time GROUP BY first_appid ORDER BY Number DESC";}//var_dump($conn);$result=mysqli_query($conn,$strsql);//var_dump($result); if(mysqli_num_rows($result)>0){echo'<table border="1" cellpadding="0" cellspacing="0">';echo'<tr>';echo'<th>Order</th>';echo'<th>AppId</th>';echo'<th>Number</th>';echo'<th>Percent</th>';echo'</tr>';$index=1;while($row=mysqli_fetch_row($result)){echo'<tr>';echo'<td align="center">';echo$index++;echo'</td>';echo'<td bgcolor="#FFFFFF" align="center">';if($row[0]==''){echo'无';}else{echo$row[0];}echo'</td>';echo'<td bgcolor="#FFFFFF" align="center">';echo$row[1];echo'</td>';echo'<td bgcolor="#FFFFFF" align="center">';$percentage=$total==0?0:$row[1]/$total;echosprintf("%.2f%%",$percentage*100);echo'</td>';echo'</tr>';}echo'</table>';echo'<p>总计 '.$total.'</p>';echo'查询完成, 操作时间 '.date("Y-m-d H:i:s",time());}else{echo'记录为空!';}mysqli_free_result($result);mysqli_close($conn);