<?php
// goping on "$xcityid is the variable that is mysql_query for State name." State name = Alabama? or 2?
$states = array("alabama", "alaska");
foreach($states as $numberRepresentingState => $state)
{
if($state==$xcityid)
{
$xcityidNo = $numberRepresentingState;
break;
}
}
//alabama would be 2, alaska would be 3
// so below alabama would be 2.gif
if (file_exists("city/".$imgId.".gif"))
{
echo "<img src=\"city/".$imgId.".gif\" width=\"80\" height=\"80\" alt=\"".$xcityid." state flag\" />";
}
?>
I think that should work, haven't tested it cause really I don't need a snippet like this, although, I don't think i can find a problem with that.
I would definitely design a function that you can call that relates to all images required by the site and a separate function that verifies the the files existence thus saving duplicated code. image class of some sort.
Getting back to point though, that 'should' work.