Answer the question
In order to leave comments, you need to log in
Displaying images from mysql how?
Guys can anyone help
I'm trying to make a website and there are a number of problems.
For example, I want to display pictures on the site from the database, I do everything like this
$sql_img = $db->super_query("SELECT * FROM imgtop");
foreach($sql_img as $q)
$img .= '<li style="background-image: url({theme}/img/'.$sql_img['name'].');" class="overlay"></li> ';
$tpl->set('{img}', $img);
function super_query($query, $multi = false, $cache_prefix = false, $system_cache = false){
//Если включен кеш, то проверяем на его существование
//Если есть ответ с кеша
if($data){
$unSerData = unserialize($data);
if($unSerData)
return $unSerData;
else
return array();
} else {
if(!$multi) {
$this->query($query);
$data = $this->get_row();
$this->free();
//Если включен кеш, то создаём его
if($cache_prefix){
$cache_rows = serialize($data);
mozg_create_cache($cache_prefix, $cache_rows);
}
return $data;
} else {
$this->query($query);
$rows = array();
while($row = $this->get_row()) {
$rows[] = $row;
}
$this->free();
//Если включен кеш, то создаём его
return $rows;
}
}
}
<li style="background-image: url(/system_sain/lk_system/system_tpl/komp/img/slider_1.jpg);" class="overlay"></li>
<li style="background-image: url(/system_sain/lk_system/system_tpl/komp/img/slider_1.jpg);" class="overlay"></li>
Answer the question
In order to leave comments, you need to log in
1. It seems that the second argument speaks of the number, so you can try to do
2. You bypass the loop
, but you are trying to take the address to the picture from the array
with the first item, you need to look for it already in $q
$sql_img = $db->super_query("SELECT * FROM imgtop");
foreach($sql_img as $q) {
$img .= '<li style="background-image: url({theme}/img/'.$q['name'].');" class="overlay"></li> ';
}
for starters - learn syntax and PSR, which is not just invented.
foreach($sql_img as $q) //здесь должна быть открывающая {
$img .= '<li style="background-image: url({theme}/img/'.$sql_img['name'].');" class="overlay"></li> ';
// тут у вас цикл закончился и вернулся к новой итерации, это равноценно закрывающей }
// а так же нахрена вам $q если вы обращаетесь к $sql_img? и нахрена тогда вообще цикл?
$tpl->set('{img}', $img); // тут вы получили элемент массива $sql_img['name'] в каждой строчке. соответственно будет одна картинка.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question