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:
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:
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.
This is the right code in case someone needs it, which I doubt.
Moderators can close this if needed. Thanks.
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:
You must be registered to see links
<?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: