I'm no OOP programmer but maybe extend your class to
include methods for each situation.
something like this:
function countSingle($cid)
function countMulti($cidArray)
function countAll()
HTH,
olinux
--- Victor <[EMAIL PROTECTED]> wrote:
> Hello. I have this question. When I program, I try
> to create a class for
> each table. Example below.
>
> Now what some complain about, and logically so, is
> that this might
> impose an overhead (I load all data even if I just
> need a counter and
> NOT description).
>
> So I say we can make a STATIC version of each
> Accessor with $cid as
> argument; But then they say what if i want to load
> an array of all 2000
> counters, for example. I say first get all the
> $cid's, then in an array,
> load a class for each one, etc.. That however makes
> lots of SQL calls
> instead of one big one. I suppose I can get all data
> and then load it
> into classes, but that seems like a bad approach,
> especially for
> calculated values.
>
> What I am curious about is what paradigms do you
> guys use to address
> these issues? Is my paradigm good and it's worth to
> just provide static
> methods for frequently necessary fields to reduce
> overhead, or is there
> a better way of dealing with this stuff?
>
> class Counter
> {
> var $db;
>
> var $cid;
> var $counter;
> var $descr;
>
> /**
> * Default Constructor
> * @param int $cid - Counter ID
> */
> function Counter($cid=false)
> {
> global $db;
> $this->db = &$db;
> if (isset($cid) && $cid) $this->load($cid);
> }
>
> /**
> * Description
> * @param int $cid - Counter ID
> * @return bool
> */
> function load($cid=0)
> {
> if (!$cid) return false;
>
> $q = "SELECT * FROM counter WHERE cid =
> $cid";
> $r = $this->db->getRow($q); // Using PEAR
> here.
>
> if (!DB::isError($r)) {
> $this->cid = $r["cid"];
> $this->counter = $r["counter"];
> $this->descr = $r["descr"];
> return true;
> }
> return false;
> }
>
>
>
#################################################################
> # Accessor Methods
>
>
#################################################################
> function getCid() { return $this->cid; }
> function getCounter() { return $this->counter; }
> function getDescr() { return $this->descr; }
>
>
>
#################################################################
> # Mutator Methods
>
>
#################################################################
> function setCid($v) { $this->iaid = $v; }
> function setCounter($v) { $this->counter = $v; }
> function setDescr($v) { $this->descr = $v; }
>
> // Many other methods, etc.... Static methods,
> etc...
> }
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php