Reputation: 11
<?php
$connect = mysqli_connect('localhost', 'root', ' ', ' ');
if(mysqli_connect_errno($connect)){
echo 'Failed to connecto to database'.mysqli_connect_error();}
$result= mysqli_query($connect, "SELECT * FROM Products WHERE ProductCategory = 'Electronics'");
?>
<table width="500", cellpadding=5 callspacing=5 border=1>
<tr>
<th>Product Name</th>
<th>Product Price</th>
<th>Product Image</th>
<th>Product Description</th>
<th>Product Category</th>
</tr>
<?php while($rows = mysqli_fetch_array($result)): ?>
<tr>
<td><?php echo $rows['ProductName']; ?></td>
<td><?php echo $rows['ProductPrice']; ?></td>
<td><?php echo '<p<img src="images/'.$row["ProductImage"].'" />'; ?></td>
<td><?php echo $rows['ProductDescription']; ?></td>
<td><?php echo $rows['ProductCategory']; ?></td>
</tr>
<?php endwhile; ?>
</table>
My issue is that the code that I currently have only makes it so that it will run through the database line by line and get the information but when it comes to the images row then it doesn't retrieve anything and my directory is correct as the image is stored in a folder called images that is within the folder the web page is.
Upvotes: 0
Views: 85
Reputation:
<td><?php echo '<p<img src="images/'.$row["ProductImage"].'" />'; ?></td>
You forgot to close the <p
and also missing the "s"
in rows
this should be <td><?php echo '<p><img src="images/'.$rows["ProductImage"].'" /></p>'; ?></td>
also dont forget to close the <p>
tag later
Upvotes: 6
Reputation:
You're missing the "s" in rows
Try: <td><?php echo '<p><img src="images/'.$rows["ProductImage"].'" /></p>'; ?></td>
Upvotes: 0
Reputation: 36
Instead of
<td><?php echo '<p<img src="images/'.$row["ProductImage"].'" />'; ?></td>
Use below code
<td><?php
$productImage = !empty($row["ProductImage"])?$row["ProductImage"]:'no-image.png';
echo "<img src='/images/{$productImage}' />";?>
Upvotes: 0
Reputation: 60
<td><?php echo '<p<img src="images/'.$row["ProductImage"].'" />'; ?></td>
You're missing a closing > on p before img and subsequently a closing p.
Try:
<td><?php echo '<p><img src="images/'.$rows["ProductImage"].'" /></p>'; ?></td>
You can edit the size of your pictures by using CSS, if photoshop is not a solution.
Upvotes: 0