S
S
Seream2202018-06-03 13:57:37
PHP
Seream220, 2018-06-03 13:57:37

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);

So he displays a picture that is in the database, and only one he displays like that. There are 5 pictures in the database.
How can I fix this so that he would display one picture and not 2 at once one and the same?
How can I make it output from mysql all the pictures that are there and they were shown?
The request with super_query found ready because there is not much experience. While I'm learning it is written like this.
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;

      }
    
    }
  }

Can someone tell me how to fix it so that everything works fine.
It renders the picture like this.
<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>

I would also like to find a person who, for a fee, will help me. I.e. I will try to do something if something does not work out that would help explain. Preferably with a connection. There is some experience. Willingness to learn too. There is a server where I test (My computer))) Where I write from))

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Arman, 2018-06-03
@Arik

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

M
Mysterion, 2018-06-03
@Mysterion

$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> ';
}

T
ThunderCat, 2018-06-03
@ThunderCat

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 question

Ask a Question

731 491 924 answers to any question