It is necessary to make the output of the slider through a function, with the image output through the database in order / randomly. I do not know how to implement, I need help. Here is function.php:
class Functions{ public $db, $config; public function __construct($config){ $this->config = $config; $this->db = new mysqli($config['db_host'], $config['db_user'], $config['db_pass'], $config['db_name']); if ($this->db->connect_error) { die("Couldn't connect to MySQL: ".$this->db->connect_error); } mysqli_query($this->db, "SET NAMES utf8"); } public function getTemplate($name){ $file = $_SERVER['DOCUMENT_ROOT']."/template/".$name.".tpl"; if(!is_file($file)){ return "Ошибка! Шаблон не найден!"; }else{ $template = file_get_contents($file); preg_match_all('/{include file="(.*?)"}/is', $template, $matches); foreach($matches[1] as $value) { $template = str_replace('{include file="'.$value.'"}', $this->getTemplate(str_replace(".tpl", "", $value)), $template); } return $template; } } public function getIndex($template, $replace = ['from' => [], 'to' => []]){ $template = $this->getTemplate($template); $replace['from'][] = "{title}"; $replace['to'][] = $this->config['site_title']; if($this->isLogged()){ $user = $this->getUser(); $replace['from'][] = "{authBlock}"; $replace['to'][] = '<div class="userblock"> <a href="/user"> <div class="userblock-avatar"><img src="'.$_SESSION['avatarfull'].'" alt="Аватар"></div> <a href="/user" class="userblock-name">'.$_SESSION['name'].'</a> </a> <div class="userblock-bottom"> <a href="/pay" target="_blank"> <div class="userblock-money price" id="balanceTXT">'.$user->money.' ₽</div> <div class="userblock-money-text">Пополнить</div> </a> </div> <a href="/steam?logout" class="userblock-quit">x</a> </div>'; }else{ $replace['from'][] = "{authBlock}"; $replace['to'][] = '<a class="enter-steam" href="/steam?login">Войти через<br><span>Steam</span></a>'; $replace['from'][] = "{logoutBlock}"; $replace['to'][] = "/"; } return str_replace($replace['from'], $replace['to'], $template); } How does it look in my head
public function getSlider($template, $replace = ['from' => [], 'to' => []]){ $template = $this->getTemplate($template); $replace['from'][] = "{slider}"; $replace['to'][] = - **здесь должно быть что-то вроде** $slider = $this->query("SELECT * FROM slider WHERE picture='$picture' ORDER BY id"); while($slide = $slider->fetch_object()){ $slidePost .= '<div class="owl-carousel owl-theme"> <div id="'.$slide->id.'"><a href="'.$slide['href'].'" target="_blank"><img src="slider/'.$slide->picture.'" alt="'.$slide->description.'"></a> </div>'; } I do not know how to correctly write the output of the slides in order or randomly from the database, so that it generates them in {slider}. The slider table consists of id, picture (location of the slide), href, description, name.