S
S
Seream2202018-06-06 17:09:38
PHP
Seream220, 2018-06-06 17:09:38

Can't get output in php how to fix it?

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

There are 4 pictures in the database in the name table, the names of the pictures are indicated. It renders the image 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>

For some reason, he himself immediately outputs 2 pictures one and the same.
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?
I already created threads with this question. Please read the answers here How to fix in php?
In order not to ask the same questions and write such answers.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis, 2018-06-06
@sidni

1) you can write what var_dump($sql_img); will display;
2) it is more logical to think that it would be more correct to write instead of $sql_img['name'] -> $q['name']

T
ThunderCat, 2018-06-06
@ThunderCat


$sql_img = $db->super_query("SELECT * FROM imgtop limit 2", true);
print_r($sql_img);
exit;
what does it show?
Outputs an array like this
Array ( [0] => Array ( [id] => 1 [name] => slider_1.jpg ) [1] => Array ( [id] => 2 [name] => slider_2.jpg ) )
sandbox.onlinephpfunctions.com/code/9f43dc6039aa53...
result:
someone piz ... tryndit, and most likely not an interpreter)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question