Answer the question
In order to leave comments, you need to log in
Stick to OOP or is it overkill?
I'm self-taught
I made my own crutch engine and now I'm trying to make it more OOP's
There is a database:
user (user_id, image_id_avatar)
pictures (image_id, image_src)
There is a User class:
private $users = [];
private $user = [];
private $userID = null;
public function __construct($userID = null, $user = [], $users = [])
{
$this->userID = $userID;
$this->user = $user;
$this->users = $users;
}
public function findBy($params = [], $multiple = false)
{
$Users = App::DB()->select('users', [], $params); //получаю данные из бд
if (count($Users)){
if ($multiple){
$this->users = $Users;
return $this;
}
if (count($Users) > 1)
return $this;
$this->user = $Users[0];
$this->userID = $Users[0]['User_ID'];
return $this;
}
return $this;
}
public function refactor($options = [])
{
$userDB = $this->user;
$image = $userDB['Image_ID_Avatar']
? STORAGE_DOMAIN .Image::getImageByID($userDB['Image_ID_Avatar'])['Image_Path']
: null;
$this->user = [
'hash' => $userDB['User_Hash'],
'nickname' => $userDB['User_Nickname'],
'avatar' => $image
];
return $this;
}
Image::getImageByID
returns the src of the image:public static function getImageByID($image_id)
{
$Image = App::DB()->select('images', [], ['image_id' => $image_id]); // новый запрос в БД
return $Image[0];
}
Answer the question
In order to leave comments, you need to log in
Then you need to pull out all 100 users, and then pull out 100 pictures with one request, specifying an array of id-dov of the pulled users in the request for the pictures.
Or use join on both tables
In two cases, the methods for pulling out can be implemented through OOP, which does not need to be abandoned
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question