Alright, I'm working on making a Member class for my website. I want to make it as optimized as possible. Currently, the constructor can take ($resource) either an int (to grab info from one member in the database, based on id) or an array of ints (to grab multiple members from the database, and store them in an array member variable).
I would like to know if there are any inprovements I can make with my block of code below, before I move on to creating more parts of my website. What could be changed to make it better? Is there a better layout I should follow for doing this kind of thing?
public function __construct($resource) {
global $database;
if (is_string($resource) || is_int($resource)) {
$resource = (int)$resource;
$query = $database->query("SELECT * FROM members WHERE member_id = {$resource} LIMIT 1");
$row = $database->get_row($query);
foreach ($row as $key => $value) {
$this->field[$key] = $value;
}
} else if (is_array($resource)) {
$query = $database->query("SELECT * FROM members WHERE member_id IN(" . implode(",",$resource) . ")");
while ($member = $database->get_row($query)) {
$this->member_list[$member['member_id']] = $member;
}
}
}