Welcome to the Geeks & God Static Archive. Read more »

ALT tags for dynamic images

Joined: 11/28/2008

I using PHP/MySQL to dynamically generate most of the sites content, including some images that are stored. I heard that for SEO purposes I should have ALT tags on these images, but how if they're dynamically generated? Could I create a generic, standard alt tag to useon all my images and put it on, or will I have to store the alt tag in the MySQL?

Joined: 11/28/2008
if the content doesn't really

if the content doesn't really matter to you, then for validation purposes, you should at least have an empty alt tag.

CODE
for ( $i = 1; $i <= 10; $i++ )
{
 echo '<img src="mypic.jpg" alt="" />';
}

or, survey the other fields in the tables. is there any other useful content you can put in there like the name of the image? are they pictures of people or things? put that in the alt tag.
The purpose they had in making it required for validation is for accessibility, so you may as well do something purposeful with it.
Happy SEOing /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />

Joined: 11/28/2008
How do you generate your

How do you generate your images? If you are storing the image in a database table, why not add some info for each image. Then in your PHP code, you could spit out the img tag sonething like this:

CODE
function printimage($imgid) {
 global $db;
 # first do a query to retrieve info (dimensions/alttext) about this image, identified by $imgid
 $result = mysql_query("SELECT * FROM images WHERE ID={$imgid}",$db);
 # next write out img tag.
 if ($imginfo = mysql_fetch_array($result)) {
?>
<img src="image.php?imgid=1264" width="<?php echo $imginfo['width']; ?>" height="<?php echo $imginfo['height']; ?>" alt="<?php echo $imginfo['alt']; ?>" title="<?php echo $imginfo['alt']; ?>" />
<?php
 }
}

Paul Davey
Whitford Church
"Everyone who calls on the name of the Lord will be saved." Romans 10:13
"For all have sinned and fall short of the glory of God, and are justified

Joined: 11/28/2008
Thanks Dustin and Paul.@Paul

Thanks Dustin and Paul.

@Paul - I think that if I store lots more info it will make an originaly really simple script into something more complicated that I want to do, I think I could use it elsewhere sometime though so thanks.

@Dustin - I think I could survey the other fields like you said and just find something that would fit and add that to the alt tag.

Thanks again! /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />