sonill Posted November 19, 2008 Share Posted November 19, 2008 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 More sharing options...
trq Posted November 19, 2008 Share Posted November 19, 2008 Is the actual image stored in the database or just the path to the image file? Link to comment https://forums.phpfreaks.com/topic/133314-how-to-show-images-from-a-database/#findComment-693318 Share on other sites More sharing options...
sonill Posted November 19, 2008 Author Share Posted November 19, 2008 the images actually exists in the database, i just want to some query on how to call them from database and use it in web page. Link to comment https://forums.phpfreaks.com/topic/133314-how-to-show-images-from-a-database/#findComment-693319 Share on other sites More sharing options...
xcoderx Posted November 19, 2008 Share Posted November 19, 2008 post table structure Link to comment https://forums.phpfreaks.com/topic/133314-how-to-show-images-from-a-database/#findComment-693330 Share on other sites More sharing options...
sonill Posted November 19, 2008 Author Share Posted November 19, 2008 table structure table name: tbpictures dtabase name: spice_db 2 rows, a) pictureID - int - 11 - auto increment not null b) pictures - varchar - 100 not null primary key: pictureID Link to comment https://forums.phpfreaks.com/topic/133314-how-to-show-images-from-a-database/#findComment-693331 Share on other sites More sharing options...
xcoderx Posted November 19, 2008 Share Posted November 19, 2008 the pics are stored in dir or by image url? ??? Link to comment https://forums.phpfreaks.com/topic/133314-how-to-show-images-from-a-database/#findComment-693335 Share on other sites More sharing options...
xcoderx Posted November 19, 2008 Share Posted November 19, 2008 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; Link to comment https://forums.phpfreaks.com/topic/133314-how-to-show-images-from-a-database/#findComment-693340 Share on other sites More sharing options...
xcoderx Posted November 19, 2008 Share Posted November 19, 2008 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!"; } Link to comment https://forums.phpfreaks.com/topic/133314-how-to-show-images-from-a-database/#findComment-693353 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.