Show images of MYSQL in php

0

I'm trying to show an image for every record saved in the database. I have managed to show a square for each record, but I can not see the image.

I have a file that is events.php that is this:

<?php
include_once('conexion.php');
$consultaimg = consultaimg();
?>
Luego esta la pagina web y en el body tengo esto de php:

<div class="row">
<?php
while ($variable = $consultaimg->fetch_assoc())
{

  ?>
  <div class="col-md-4">
    <div class="thumbnail">
      <a href="#">
        <img src="<?php print $variable; ?>"  style="width:100%">
        <div class="caption">
          <p>Lorem ipsum...</p>
        </div>
      </a>
    </div>
  </div>
  <?php

}
?>

If I "inspect" my web page, in the route where the image should be, I get this:

  

Notice: Array to string conversion in C: \ xampp \ htdocs \ PaginaWebPBLlocal \ events.php on line 92

In the database I save the images with internet routes like this: https://...

    
asked by francisco 10.02.2018 в 14:08
source

3 answers

0

You need to do something like

print $variable["Nombre columna"]

Where Nombre columna contains the url of the image.

    
answered by 10.02.2018 в 14:20
0

Assuming that your SQL query is something like SELECT nombreImagen, rutaImagen FROM Imagenes; , your php should call the image path according to the corresponding column in the query, for example:

<?php while ($variable = $consultaimg->fetch_assoc()): ?>
    <img src="<?php print $variable['rutaImagen']; ?>" style="width:100%">
<?php endwhile; ?>
    
answered by 09.01.2019 в 02:23
0

In line while ($variable = $consultaimg->fetch_assoc()) an associative array is being assigned to a variable, and that is why the warning message 'Array to string conversion' is generated.

The solution therefore would be to change that line by foreach ($variable as $consultaimg->fetch_assoc()) .

    
answered by 09.01.2019 в 02:56