Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Printing the image from the MySQL database.

Junior Spellweaver
Joined
Feb 25, 2014
Messages
163
Reaction score
40
Hello guys, I recently started to work on a website. I am doing a products page but I am having a little problem with the images.

Each product has a code in the database, and I want to link that code to the respective image. For example, in my website files (../images/123.jpg) I got an image called "123.jpg", which should be linked to the product that has the "123" code.

Here is a picture of my MySQL table:

<?php
$sentencia = $conn_forum->prepare("SELECT nombre, marca, descripcion, funcion, codigo FROM productos");
$sentencia->execute();


$resultados = $sentencia->fetchAll();

foreach($resultados as $resultado) {
echo '<div class="producto">'
.'<h3 class="titulo-producto">' . $resultado['nombre'] . '</h3>'
.'<img class="image-producto" src="/images/productos/"' . $resultado['codigo'] . '.jpg' '/>'
.'<h4 class="marca-producto">' . "Marca: " .$resultado['marca'] . '</h4>'
.'<p class="descripcion-producto">' . $resultado['descripcion'] . '</p>'
.'</div>';
}
?>

This is what I am using to fetch the products from the table, it throws the information, but I don't know how to do the image part.

As you can see, I have tried this:
PHP:
echo '<img class="image-producto" src="/images/productos/"' . $resultado['codigo'] . '.jpg' '/>';

But still no results, the image doesn't show.

Hope you guys could help me.

Thanks.



Already fixed it, I made a mistake on the code and the images path lol.

'<img class="image-producto" src="/med/images/productos/' . $resultado['codigo'].'.jpg"' . '/>'

This is the right code in case someone needs it, which I doubt.

Moderators can close this if needed. Thanks.
 
Last edited:
Newbie Spellweaver
Joined
Nov 18, 2015
Messages
31
Reaction score
4
i sugest use double quotes for echo since it's easier to split single and double quotes if you mix php in the echo. :) hope it helps. :D
 
Back
Top