Displaying Image from a Multiple Tables Select Query.

Below is a page which is supposed to output the name, blog contribution and picture of contributing members of a website.
[php][php]

<?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //include the config file require_once("config.php"); //Define the query. Select all rows from firstname column in members table, title column in blogs table,and entry column in blogs table, sorting in ascneding order by the title entry, knowing that the id column in mebers table is the same as the id column in blogs table. $sql = "SELECT blogs.title,blogs.entry,members.firstname,images.image FROM blogs LEFT JOIN members ON blogs.member_id = members.member_id LEFT JOIN images ON blogs.member_id = images.member_id ORDER BY blogs.title ASC "; $query = mysql_query($sql); if($query !== false && mysql_num_rows($query) > 0) { while(($row = mysql_fetch_assoc($query)) !== false) { echo '<div id="blog_content1" style="float:left; position:relative;bottom:18px;left:13px; background-color: #FFFFFF; height:16.7%; width:100%; border:0px none none;"
'; echo "

".$row['title']."

"; echo "

" .$row['entry']."
".$row['firstname']."

"; echo '
'; } } else if($query == false) { echo "

Query was not successful because:".mysql_error()."

"; echo "

The query being run was \"".$sql."\"

"; } else if($query !== false && mysql_num_rows($query) == 0) { echo "

The query returned 0 results.

"; } mysql_close(); //Close the database connection. ?>
                    </div> <!-- closes blog content-->[/php][/php]

The select query is designed to retrieve all the blog contributions(represented by the fields blogs.title and blogs.entry) from the database, alongside the contributing member (member.firstname) and the member’s picture(images.image), using the member_id column to join the 3 tables involved, and outputs them on the webpage. The title, entry and firstname values are successfully displayed on the resulting page. However, I can’t seem to figure out how to get the picture to be displayed. Note that the picture was successfully stored in the database and I was able to view it on a separate page using a simple select query. It is now just a question of how to get it to display on this particularly crowded page. Anyone knows how I can output the picture in the img tag? I tried placing the header(“Content-type: image/jpeg”); statement at the top of the php segment, then just right below the select query and finally just right above the img tag, but in every case, I just got a big white blank page starring at me. How and where should I place the header statement? And what else am I to do to get this picture displayed? Any help is appreciated.

change your img tag:
[php][/php]
take out the header and just add the path to the folder that stores the image.
you also need to change it slightly because inside quote marks “” we have to wrap $row[‘image’] inside squiggly brackets {} or concatenate it “” . $row[‘image’] . “” choice is yours.

Hope that makes sense
:wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service