Jump to content

Display Images from DB


matrixx1

Recommended Posts

I'm creating a funeral home site and on the side of the page I would like to display the last 5 funeral obituaries that are in mySQL database (name and certain sized image (images are in "image" field) w/ a link to an "obituaries detail page for the individual deceased person"). I am able to do this successfully listing only the names....how can I list the image associated with the name? This is what I have so far:

 

<?php 

include("connect.php"); 

?>

 

 

<?php 

$query = "SELECT id, deceased_name, deceased_date, DATE_FORMAT(deceased_date, '%M %D, %Y') as datetext"; 
$query .= " FROM scales_obits ORDER BY deceased_date DESC LIMIT 5"; 

$listings = mysql_query($query); 
if (!listings) { 
        echo("<p>Error retrieving listings from lookup table<br>". 
                "Error: " . mysql_error()); 
        exit(); 
} 

echo("<table border=\"0\" width=\"100%\" class=\"obit\">"); 

while ($listing = mysql_fetch_array($listings)) { 

$deceased_name = $listing["deceased_name"]; 
$deceased_date = $listing["datetext"]; 
$id = $listing["id"]; 

echo("<tr><td width=\"100%\"><a href=\"obitdetail.php?id=".$id."\"><strong>".$deceased_name."</strong></a></td><td> </td>"); 


} 

echo("</table>"); 
?>

Link to comment
Share on other sites

You'll have to select the `image` column from the database as well:

$query = "SELECT id, image, deceased_name, deceased_date, DATE_FORMAT(deceased_date, '%M %D, %Y') as datetext";

Then echo it with the other things:

$image = $listing["image"];

echo("<tr><td width=\"100%\"><a href=\"obitdetail.php?id=".$id."\"><img src=\"".$image."\" alt=\"".$deceased_name."\"><br><strong>".$deceased_name."</strong></a></td><td> </td>");

Link to comment
Share on other sites

  • 1 year later...

I'm doing something very similar, but I need to organize my images into seperate tabs based on their date. As it is now, all my tabs show up for all the existing dates but all my images for each specific person retrieved by my query show up on the first tab. So i guess I need them to be sorted by the dates and then inserted into each corrosponding tab. How can I do this?

 

Any help is appreciated. Thanks

Edited by reubencanowski
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.