本文介绍了PHP脚本获取月份错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I有一个statcounter在我的网站上显示的观点和访问,直到上个月......但由于某些原因,它只显示直到5月份,你可以看到这里:





我不知道最新的错误....

这是我的代码:


$ (日期('H'),日期('i'),日期('s'),((m),mktime,日期('m') - 12),日期('d'),日期('Y'))));
$ old_year = strtolower(日期(​​Y,mktime(日期('H'),日期('i'),日期('s'),(日期('m') - 12) ('d'),日期('Y'))));

// echo'< p>'。$ profile_stats ['month']。'< / p>';
// echo'< p>'。$ old_month。'< / p>';
// echo'< p>'。$ profile_stats ['year']。'< / p>';
// echo'< p>'。$ old_year。'< / p>';
$ b $ if if($ profile_stats ['month']< $ old_month&& $ profile_stats ['year'] == $ old_year
|| $ profile_stats ['month'] = = date('m')&& $ profile_stats ['year'] == date('Y')){
?>

<?php
}
else {

if($ profile_stats ['month'] == 1){
$ mname1 ='一月';
}
elseif($ profile_stats ['month'] == 2){
$ mname1 ='Feburary';
}
elseif($ profile_stats ['month'] == 3){
$ mname1 ='March';
}
elseif($ profile_stats ['month'] == 4){
$ mname1 ='April';
}
elseif($ profile_stats ['month'] == 5){
$ mname1 ='May';
}
elseif($ profile_stats ['month'] == 6){
$ mname1 ='June';
}
elseif($ profile_stats ['month'] == 7){
$ mname1 ='July';
}
elseif($ profile_stats ['month'] == 8){
$ mname1 ='August';
}
elseif($ profile_stats ['month'] == 9){
$ mname1 ='September';
}
elseif($ profile_stats ['month'] == 10){
$ mname1 ='October';
}
elseif($ profile_stats ['month'] == 11){
$ mname1 ='November';
}
elseif($ profile_stats ['month'] == 12){
$ mname1 ='December';
}

if($ profile_stats ['month'] == date('m')&& $ profile_stats ['year'] == date('Y')) {
$ mname1 =< i>当月< / i> - $ mname1;
}
if($ profile_stats ['month'] == 04&& $ profile_stats ['year'] == 2012){
$ newstats_alert =< p>< ; b style ='color:red;'>< i> 2012年4月的统计数据仅部分归因于月中实施此功能。< / i>< / b>< / p>;
}
else {
$ newstats_alert = NULL;
}
?>


< tr>
< td colspan ='4'style ='border:2px solid black;'>< div align =center>< b>< u><?= $ mname1?> ; < = $ profile_stats [年]>?< / U>< / B>< = $ newstats_alert>?< / DIV>< / TD>
< / tr>
< tr>
< td>个人资料视图< / td>
< td>课程视图< / td>
< td>一般咨询< / td>
< td>课程查询< / td>
< / tr>
< tr>
< td><?=($ profile_stats ['profile_views'] + 0)?>< / td>
< td><?=($ course_views [$ profile_stats ['year']。 - 。$ profile_stats ['month']] + 0)?>< / td>
< td><?=($ profile_stats ['general_enquiries'] + 0)?>< / td>
< td><?=($ course_enquiries [$ profile_stats ['year']。 - 。$ profile_stats ['month']] + 0)?>< / td>


请帮我解决这个问题。

I have a statcounter on my website which displays the views and visits till the last month...but for some reasons, it is showing only upto May month as you can see here:

http://tinypic.com/r/ea1kjm/6

I dont know whats wrong....

This is my code for this:

$old_month = strtolower(date("m", mktime(date('H'), date('i'), date('s'), (date('m')-12), date('d'), date('Y'))));
$old_year = strtolower(date("Y", mktime(date('H'), date('i'), date('s'), (date('m')-12), date('d'), date('Y'))));

//echo '<p>'.$profile_stats['month'].'</p>';
//echo '<p>'.$old_month.'</p>';
//echo '<p>'.$profile_stats['year'].'</p>';
//echo '<p>'.$old_year.'</p>';

                    if ( $profile_stats['month'] < $old_month && $profile_stats['year'] == $old_year
                    || $profile_stats['month'] == date('m') && $profile_stats['year'] == date('Y') ) {
                    ?>

<?php
                    }
                    else {

                        if ( $profile_stats['month'] == 1 ) {
                        $mname1 = 'January';
                        }
                        elseif ( $profile_stats['month'] == 2 ) {
                        $mname1 = 'Feburary';
                        }
                        elseif ( $profile_stats['month'] == 3 ) {
                        $mname1 = 'March';
                        }
                        elseif ( $profile_stats['month'] == 4 ) {
                        $mname1 = 'April';
                        }
                        elseif ( $profile_stats['month'] == 5 ) {
                        $mname1 = 'May';
                        }
                        elseif ( $profile_stats['month'] == 6 ) {
                        $mname1 = 'June';
                        }
                        elseif ( $profile_stats['month'] == 7 ) {
                        $mname1 = 'July';
                        }
                        elseif ( $profile_stats['month'] == 8 ) {
                        $mname1 = 'August';
                        }
                        elseif ( $profile_stats['month'] == 9 ) {
                        $mname1 = 'September';
                        }
                        elseif ( $profile_stats['month'] == 10 ) {
                        $mname1 = 'October';
                        }
                        elseif ( $profile_stats['month'] == 11 ) {
                        $mname1 = 'November';
                        }
                        elseif ( $profile_stats['month'] == 12 ) {
                        $mname1 = 'December';
                        }

                        if ( $profile_stats['month'] == date('m') && $profile_stats['year'] == date('Y') ) {
                        $mname1 = "<i>Current Month</i> - $mname1";
                        }
                        if ( $profile_stats['month'] == 04 && $profile_stats['year'] == 2012 ) {
                        $newstats_alert = "<p><b style='color: red;'><i>April 2012 stats are only partial due to implementation of this feature mid month.</i></b></p>";
                        }
                        else {
                        $newstats_alert = NULL;
                        }
                    ?>


   <tr>
<td colspan='4' style='border: 2px solid black;'><div align="center"><b><u><?=$mname1?> <?=$profile_stats['year']?></u></b><?=$newstats_alert?></div></td>
    </tr>
 <tr>
<td>Profile Views</td>
<td>Course Views</td>
<td>General Enquiries</td>
<td>Course Enquiries</td>
 </tr>
  <tr>
<td><?=($profile_stats['profile_views'] + 0)?></td>
<td><?=($course_views[$profile_stats['year']."-".$profile_stats['month']] + 0)?></td>
<td><?=($profile_stats['general_enquiries'] + 0)?></td>
<td><?=($course_enquiries[$profile_stats['year']."-".$profile_stats['month']] + 0)?></td>

Please help me to solve this.

解决方案

The (date('m')-12) will return a negative value usually. This is probably why you're getting an odd result.

这篇关于PHP脚本获取月份错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 20:41