Monday, 29 January 2007
Article: Create a DIY Control in PHP |
| |
|
| |
Over at the NewsForge web site, Donald W. McArthur shows you how to create a DIY calendar control in PHP. He informs you that on a recent project he needed to display a calendar with dates serving as hyperlinks to selected database items. He decided to use the opportunity to write some portable PHP code that he could use in other projects too.
He says his design goals were to create a PHP page that would take as input a querystring value in the form of a UNIX epoch number that would represent the starting point of a particular date. He chooses the UNIX epoch number, which represents the number of seconds that have transpired since the start of January 1, 1970. This was also his data, which his database SQL statement used as SELECT criteria. The script would determine the month and year of that value, and create an array holding a UNIX epoch number for the beginning moment for each day in that month. The script would then output HTML to display a calendar, with each date a hyperlink back to the original PHP page, with the associated querystring value for that date he explains.
He informs you that the code turned out to be compact, and can be customizable for anyone's particular needs. He also chose an HTML embedded table to hold the calendar output, as some difficulties was found using a grid of Cascading Style Sheet (CSS) settings to hold closely spaced data when it contains hyperlinks. But he did use CSS for font selection and on-page positioning of the embedded table.
He provides the PHP code that he uses to handle the querystring appended to the URL in the following format:
http://www.yoursite.com/calendar.php?dts=1167631200
He also provides a code example to handle the querystring. He says PHP provides two built-in functions for managing dates and timestamps—date() and mktime(). The PHP date() function takes either one or two arguments. The first is for formatting. The second, if included, is an Unix epoch number to process. The PHP mktime() function takes as arguments the hour, minute, second, month, day, and year, and returns a Unix epoch number. All these he shows with code examples. Additionally he also shows how to conceptualize a monthly calendar as a matrix. |
| |
|
Read the Article
|
| |
|
|
| |
|
|
| |
|