Use MySQL result to display an image.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
michaeljohnh
Forum Newbie
Posts: 1
Joined: Mon Nov 29, 2010 8:38 am

Use MySQL result to display an image.

Post by michaeljohnh »

Hello

Novice to PHP but trained in MySQl and HTML.

I am trying to perform a query and have the result be used as the file name for an image that is saved in the same directory as the PHP doc. That image is to then be display in the page. Examples of those entries in that field in MySQL are image1.jpg, image2.jpg etc.

The table name is images and the two field are worldpos and picture. Here is the relevant portion of the code (I omitted the login portion because login is sucessful)

mysql_select_db($db_database)
or die("Unable to select database: " . mysql_error());

$query = "SELECT picture FROM images WHERE worldpos=1";
$result = mysql_query($query);

if (!$result) die ("Database access failed: " . mysql_error());

What I need is the code that will take that result and use it as a text field to indicate which image should be displayed. I tried plugging the result into an img src statement but cant make it work.

Thank you in advance for any assistance.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Use MySQL result to display an image.

Post by Celauran »

Code: Select all

list($imagename) = mysql_fetch_row($result);
Post Reply