Jump to content

how to show images from a database


sonill

Recommended Posts

hey i m new in php and wanted to know how to show a image from a database to a web page, i know how to connect to a database, i just wanted query for displaying images, my database name is : spice_db and table name is tbpictures with two fields: a) ID & b) pic. i hope some one can help.

Link to comment
https://forums.phpfreaks.com/topic/133314-how-to-show-images-from-a-database/
Share on other sites

i found someting u can use according to ur needs

 

//connect to mysql with your variables here...
//execute your sql query(s), store result in $result

//make a table to hold images and data
$output = "<table width=\"300\">";

//fetch each row of data
while($row = mysql_fetch_array($result))
{
//do something with each row of data
//refer to columns holding data as $row['columnName'];

//for example...


//fill table with data...be sure to refer to the column/field names in your database table!

$output .= ("
<tr>
	<td><img src =\" ". $row['imageURL'] . "\"></td>
	<td>". $row['imageTitle'] . "</td>
</tr>		
")


}

//close table tag
$output .= "</table>";

//display output
echo $output;

or maybe something like this?

 

$sql = "SELECT pictures FROM tbpictures ORDER BY pictureID DESC LIMIT 1";
$reslut = @mysql_query($sql) or die("Query failed");

if($row = mysql_fetch_assoc($reslut)) {    

  echo $row['pictures'];
}
else {
   echo "error fetching picture!";
}

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.