Forum Moderators: coopster
SELECT
field1, field2, CONCAT( field2, ".jpg" ) AS imageurl
FROM sometable
ORDER BY somefield
Notice I'm using MySQL's CONCAT function to take the string in the `field2` field and append the .jpg extension onto it. Then I use an ALIAS in the SELECT so that the "bob.jpg" string (or whatever) that the CONCAT function creates has a name you can access in your resultset.
You can do a similar thing in PHP with just the concatenation operator ".", after the SELECT statement has pulled down the `field2` field data, e.g.
// assumes a valid query statement and resultset here
while( $row= mysql_fetch_assoc($result) ) {
$imageurl= $row['field2'] . ".jpg";
echo "<img src=\"$imageurl\" />";
}
This all assumes, of course, that you're using MySQL, but it can be easily adapted to any database.