You are here: Re: Queries from inside classes « PHP Programming Language « IT news, forums, messages
Re: Queries from inside classes

Posted by NC on 05/18/06 00:49

TristaSD wrote:
>
> I've got a class that builds a calendar for the current month.
> I have an extending class that adds links to all days in the
> calendar via browser querystring.
>
> My goal is to create links not to every single day, but only
> to days that satisfy a certain condition - very similar to blog
> calendars with posting dates highlighted. No post on that
> day - the date is not highlighted.
>
> I have to run a query from the extending class, which is
> totally new to me. Any pointers?

Let's say that right now you have a class defined as follows:

class Calendar {
var $month;
var $year;
... other class members...
function render() {
}
}

When you call Calendar::render(), it renders the calendar for the month
defined by $year and $month. To achieve what you want, you need to
modify Calendar::render() and pass it, let's say, an array of integers,
each signifying the day of the month that should be specially marked
(e.g., days on which posts were added to a blog). So you would have
something like this:

class Calendar {
var $month;
var $year;
... other class members...
function render($special = array()) {
$days = date('t', strtotime("{$this->year}-{$this->month}-01"));
// output the table heading...
// output blank cells before the first of the month, if any...
for ($i = 1; $i <= $days) {
if (in_array($i, $special)) {
// output a specially formatted cell
} else {
// output a "normal" cell
}
}
// output blank cells after the last of the month, if any...
}
}

Cheers,
NC

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация