Reputation: 85
I want to display images on my view from mysql path. In my mysql table i have row called imgpath and the file location is assets/images/acura_1.jpg It's displaying the car information correctly from the table but the actual image is not showing up? Thanks!
Here is my code in the view
<h1>Our Current Cars:</h1>
<?php foreach($images as $row)
{
echo "<br/>";
?> <img src = <?php echo $row->imgpath; ?> >
<?php "<br/> ";
echo "<br/>";
echo "<font color = 'red'>";
echo $row->car_year . " " . $row->car_make . " " . $row->car_model . "<br/>";
echo "Lease Term: " . $row->car_lease . " Months" . "<br/>";
echo "Base Payment: " . "$" . $row->car_payment . "<br/>" ;
echo "</font>";
}
?>
Upvotes: 0
Views: 1109
Reputation: 91744
My guess would be that you are not in the root of the web-site and the /assets
folder is.
You can use absolute paths for your images:
<img src = "/<?php echo $row->imgpath; ?>" >
^ here
If some images might start with a slash, you could use ltrim
to get rid of them:
<img src = "/<?php echo ltrim($row->imgpath, '/'); ?>" >
Upvotes: 1