Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> v2.3 RN Feedback/Suggestions
Author Message
ToolBox
Regular
Regular


Joined: Mar 16, 2005
Posts: 74

PostPosted: Thu Jun 25, 2009 5:15 pm Reply with quote

For Fun III - depreciated mktime() and date field

Have you looked at mktime() calls in php codes of phpnuke?
If so, we may find when and where the function is called.
Probably, we will find it around date field while reading DB.

For instance, look at the following codes from news stories_archive module.

Code:


   while($row = $db->sql_fetchrow($result)) {
      $time = $row['time'];
      ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $time, $getdate);
      if ($getdate[2] == "01") { $month = _JANUARY; } elseif ($getdate[2] == "02") { $month = _FEBRUARY; } elseif ($getdate[2] == "03") { $month = _MARCH; } elseif ($getdate[2] == "04") { $month = _APRIL; } elseif ($getdate[2] == "05") { $month = _MAY; } elseif ($getdate[2] == "06") { $month = _JUNE; } elseif ($getdate[2] == "07") { $month = _JULY; } elseif ($getdate[2] == "08") { $month = _AUGUST; } elseif ($getdate[2] == "09") { $month = _SEPTEMBER; } elseif ($getdate[2] == "10") { $month = _OCTOBER; } elseif ($getdate[2] == "11") { $month = _NOVEMBER; } elseif ($getdate[2] == "12") { $month = _DECEMBER; }
      if ($month != $thismonth) {
         $year = $getdate[1];
         echo "<li><a href=\"modules.php?name=$module_name&amp;sa=show_month&amp;year=$year&amp;month=$getdate[2]&amp;month_l=$month\">$month, $year</a>";
         $thismonth = $month;
      }
   }


After reading the date-time field, most codes chop down the field data from an array (string array) to individual array.
This is ineffecient and sucks sever CPU time in the following respects:

1. more codes
2. more processing

Now, there is a way to read DB time and date field into array but to variables directly, which is more faster and shorter code:
The key to pay attention is sql queries:

Code:


   $result = $db->sql_query("SELECT time from ".$prefix."_stories order by time DESC");


By the way, why this query is not good?
As you may or may not pay attention to the time-date format in stories archive, topics, and even news module, all date-time format was displayed as follows:

Year - Month - Day ....

This format is an Europen and Asian format of time and date.

To change the format, mktime() function calss entails.

To avoid and make it efficient, I would like to think over the following alternative.

Code:


   $sql = "SELECT date_format(`time`,'%Y') AS s_year, count(`sid`) AS s_nArticles FROM ".$prefix."_stories GROUP BY date_format(`time`, '%Y') ORDER BY date_format(`time`, '%Y') DESC";

Now, what happens?
This is a sample code which you can expand it like:

Code:


SELECT data_format(`time`, '%Y') AS s_year, data_format(`time`, '%M`) ......


If we want, we may combine the format of yer, month, day, etc.

With this code, we will add time-date format constant string in language files.
This means, with time-date format constant string in language files, in multi-lingual modes of NUKE, it will display in correct locale formats.

Another side effects of this idea are 1) less or no calls of mktime() function and reduced phpcode lines.

That's a just fun to think over.
 
View user's profile Send private message
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> v2.3 RN Feedback/Suggestions

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©