I'm trying to show some images on a website that I'm building. I have uploaded all the images to my server and have created a database using phpmyadmin in which I list all the path/file names for each image.
This is the code I have tried so far:
$result = mysqli_query($con,"SELECT Image,Product,Prijs,Description FROM Products order by Product ASC LIMIT 0, 5");
echo '<table border="1px solid black" cellspacing="0" style="margin-top:47px"><tbody>';
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td rowspan='2' width= '200'>" . <'img src=$row['Image']'> . "</td>";
echo "<td><b>" . $row['Product'] . "</b></td>";
echo "</tr>";
echo "<tr>";
echo "<td>" . $row['Description'] . " <i>Price: € " . $row['Price'] . "</i><br/> <br/></td>";
echo "</tr>";
}
Now it shows the product name, price, description, but no image. I'm pretty new to this so I was hoping someone here could help me out :) Any suggestions?
You have a syntax error here:
echo "<td rowspan='2' width= '200'>" . <'img src=$row['Image']'> . "</td>";
Should be
echo "<td rowspan='2' width= '200'><'img src='" . $row['Image'] . "'></td>";
Needed to close the quotes before declaring the variable. Or:
echo "<td rowspan='2' width= '200'><'img src='$row['Image']'></td>";
don't close them. Variables can be used in double quotes.
The problem is that $row['Image'] is rendered as html. It should be:
echo "<td rowspan='2' width= '200'><img src='" . $row['Image'] . "'></td>";
So the codes ends like:
$result = mysqli_query($con,"SELECT Image,Product,Prijs,Description FROM Products order by Product ASC LIMIT 0, 5");
echo '<table border="1px solid black" cellspacing="0" style="margin-top:47px"><tbody>';
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td rowspan='2' width= '200'><img src='" . $row['Image'] . "'></td>";
echo "<td><b>" . $row['Product'] . "</b></td>";
echo "</tr>";
echo "<tr>";
echo "<td>" . $row['Description'] . " <i>Price: € " . $row['Price'] . "</i><br/> <br/></td>";
echo "</tr>";
}