$active_count1_end=date('Y-m-d');
$active_count1_end.=" 23:59:59";
$active_count1_start=date('Y-m-d');
$active_count1_start.=" 00:00:00";
$count10=$today->query("select count(*) as count1 from talk where time1 between '". $active_count1_start."' and '".$active_count1_end."'");
$count11=$today->query("select count(*) as count2 from reply where time2 between '". $active_count1_start."' and '".$active_count1_end."'");
$count1=$count10[0][count1]+$count11[0][count2];
$active_count2_end=strtotime($active_count1_end)-24*3600;
$active_count2_end=date('Y-m-d',$active_count2_end);
$active_count2_end.=" 23:59:59";
$active_count2_start=strtotime($active_count1_end)-24*3600;
$active_count2_start=date('Y-m-d',$active_count2_start);
$active_count2_start.=" 00:00:00";
$count20=$today->query("select count(*) as count1 from talk where time1 between '". $active_count2_start."' and '".$active_count2_end."'");
$count21=$today->query("select count(*) as count2 from reply where time2 between '". $active_count2_start."' and '".$active_count2_end."'");
$count2=$count20[0][count1]+$count21[0][count2];
$active_count3_end=strtotime($active_count2_end)-24*3600;
$active_count3_end=date('Y-m-d',$active_count3_end);
$active_count3_end.=" 23:59:59";
$active_count3_start=strtotime($active_count2_end)-24*3600;
$active_count3_start=date('Y-m-d',$active_count3_start);
$active_count3_start.=" 00:00:00";
$count30=$today->query("select count(*) as count1 from talk where time1 between '". $active_count3_start."' and '".$active_count3_end."'");
$count31=$today->query("select count(*) as count2 from reply where time2 between '". $active_count3_start."' and '".$active_count3_end."'");
$count3=$count30[0][count1]+$count31[0][count2];
$active_count4_end=strtotime($active_count3_end)-24*3600;
$active_count4_end=date('Y-m-d',$active_count4_end);
$active_count4_end.=" 23:59:59";
$active_count4_start=strtotime($active_count3_end)-24*3600;
$active_count4_start=date('Y-m-d',$active_count4_start);
$active_count4_start.=" 00:00:00";
$count40=$today->query("select count(*) as count1 from talk where time1 between '". $active_count4_start."' and '".$active_count4_end."'");
$count41=$today->query("select count(*) as count2 from reply where time2 between '". $active_count4_start."' and '".$active_count4_end."'");
$count4=$count40[0][count1]+$count41[0][count2];
该代码用于制作论坛,
$count1
是今天的数据,
$count2
是昨天的数据,
$count3
...,
$count4
...
当然,代码没有错误,但看起来不太好。
你有代码的优化方法吗?