<?php class Categories implements Iterator, Countable { protected $result; protected $current = true; function __construct($result) { include_once 'Category.php'; $this->result = $result; } function current() { if ($this->current === true) { $this->next(); } return new Category($this->current['id'], $this->current['title']); } function next() { $this->current = $this->result->fetch_assoc(); } function key() { $current = $this->current(); return $current['id']; } function count() { return $this->result->num_rows; } function valid() { if ($this->current) { return true; } return false; } function rewind() { $this->result->data_seek(0); } } ?>