Reputation: 189
Is it acceptable to store the img src="".... for an image in a database table column, or should only the location be stored and then somehow manipulated through javascript to load the image on the webpage?
Upvotes: 0
Views: 60
Reputation: 15509
you would only store the image path (and possibly also the alt text and title) in the db and then add it into the webpage using php when the page loads. Note that in the following I am echoing each attribute independently. You can also put the entire image line inside an echo statement and cut out a couple of echoes with just the php db values listed as the attribute values.
//your mechanism of getting the data from the db
$imagePath=$Row["imagePath"]; //for example "images/common/logo.jpg";
$imageAlt=$Row["imageAlt"]; //for example "Our Company logo image";
$imageTitle=$Row["imageTitle"]; //for example "Our Company logo for 2016";
//image section of your HTML
<img src='<?php echo "$imagePath";?>' alt='<?php echo "$imageAlt";?>' title='<?php echo "$imageTitle";?>' height='50' width='50'/>
this will render as
<img src='images/common/logo.jpg' alt='Our Company logo image' title='Our Company logo for 2016' height='50' width='50'/>
Upvotes: 1