I think I'd be inclined to make two separate classes, as they represent different sorts of objects: one being a single entry and the other being a group of entries. You could use an abstract class to define the common attributes, something like:
<?php
abstract class Notes
{
protected $connection;
protected $data = array();
protected function __construct(mysqli $connx)
{
$this->connection = $connx;
}
public function getData()
{
return $this->data;
}
}
class OneNote {
private $entry;
public function __construct(mysqli $connection, $id) {
parent::__construct($connection);
$this->entry = $id;
$this->getEntry();
}
private function getEntry() {
$query = "SELECT id, col1, col2, col3 FROM notes WHERE id = ?";
$statement = $this->connection->prepare($query);
$statement->bind_param('s', $this->id);
$statement->execute();
$statement->bind_result($id, $val1, $val2, $val3);
if($statement->fetch())
{
$this->data = array(
'id' => $id,
'col1' => $val1,
'col2' => $val2,
'col3' => $val3
);
}
}
public function getData()
{
return $this->data;
}
}
class AllNotes {
public function __construct(mysqli $connection) {
parent::__construct($connection);
$this->getEntry();
}
private function getEntry() {
$query = "SELECT id, col1, col2, col3 FROM notes ORDER BY ID DESC";
$statement = $this->connection->prepare($query);
$statement->execute();
$statement->bind_result($id, $val1, $val2, $val3);
while($statement->fetch())
{
$this->data[$id] = array( // create 2-dim array
'id' => $id,
'col1' => $val1,
'col2' => $val2,
'col3' => $val3
);
}
}
}
?>