Jump to content

Retrieving pics from a database


johnnyblaze9

Recommended Posts

I've been trying to retrieve user specific pics from a sql database, and have been given some good advice already, but I can't seem to figure out how to display a picture that I have in a database.  When a client logs into my website, I need pictures of his product to be displayed on the page.  How do I run a query and then display those results if they are images?

Link to comment
https://forums.phpfreaks.com/topic/102637-retrieving-pics-from-a-database/
Share on other sites

Im assuming uve saved in the db the filepath of the images for your users, so getting them shouldnt be difficult. If u need to save several pictures for one client, u can save all of them in one row seperated by a comma (or other characters) or have a different table for the images with a user_id column. A simple scenario:

 

users table

----------

id | username | password

 

photos table

------------

id | path | user_id

 

Where photos.user_id references users.id

 

<?php
if($is_logged == true){ //just for example's sake
    $userID = 10;
    $resultsPhotos = mysql_query("SELECT path FROM photos WHERE user_id=$userID");
    while($valuesPhotos = mysql_fetch_array($resultsPhotos)){
         echo "<img src='user_photos/" . $valuesPhotos['path'] . "'";
         echo '<br /><br />'
    }
}
?>

 

Hope thats what u needed.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.