From: K. O. <on...@xo...> - 2003-06-06 03:25:59
|
Hi, Did you have problem using the criteria class? Thanks and regards, K. Ono ---------------------------------------------------------------------------- - /** * load objects from database * * Note: doesn't use Criteria because that class needs a WHERE clause * * @param int $limit * @param int $start * @param bool $id_as_key should the ID be used as the array key? * @param string $sql_clause arbitrary where/order by clause (overrides default sorting) * @return array array of references to objects */ function &fetch($limit=0, $start=0, $id_as_key=false, $sql_clause=null) { $objects = array(); $limit = $start = 0; $sql = 'SELECT * FROM '.$this->table; if ($sql_clause) { $sql .= ' '.$sql_clause; } else { if ($this->sort) { // could do caching of ORDER BY clause $sql .= ' ORDER BY '; $scnt = count($this->sort); for ($i=0; $i < $scnt; $i++) { $sql .= $this->sort[$i].' '.$this->sortOrder[$i]; if ($i+1 < $scnt) $sql .= ', '; } } } $result = $this->db->query($sql, $limit, $start); if (!$result) { return $objects; } while ($myrow = $this->db->fetchArray($result)) { $object = new $this->class(); $object->assignVars($myrow); if (!$id_as_key) { $objects[] =& $object; } else { $objects[$myrow[$this->id]] =& $object; } unset($object); } return $objects; } -------------------------------------------------------------------------- |