having problem in displaying all the images from database

Alles, was PHP betrifft, kann hier besprochen werden.

having problem in displaying all the images from database

Postby gabyap1390 » 23. September 2011 16:32

hello guys, im having a hard time displaying images from my database to my webpages
ill make it short so here the codes

my process in displaying BLOB images

Code: Select all
//here's the code where i retrieve the image from database
require_once 'conff.php';

if (IsSet($_GET['Paint_ID'])){
 $gotten = @mysql_query("select Image from paintings where Paint_ID = ".$_GET['Paint_ID']);
 header("Content-type: image/jpeg");
 while ($row = mysql_fetch_array($gotten)) {
 print $row['Image'];

here's the other one with <img tag>

Code: Select all
//nothing special from here

require_once 'conff.php';
require_once 'server.php';

function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
 } else {
 return $pageURL;

//ssetting up another URL for painters
$cURL = curPageURL();
         //$url = strpos($cURL,)
         $sub = substr($cURL, -1); //get the last # of any page// <<--- until here, codes just to get the last # //of the URL

      //paintings list
         $query = mysql_query("SELECT * FROM paintings WHERE Paint_ID='".$sub."'");
         $nums = mysql_num_rows($query);
         if($nums == 0){ echo '</br>'.'no photo'; } else if($nums >= 1) {
         while(($rows = mysql_fetch_assoc($query))) {
            $paint = $rows['Image'];
            $title = $rows['Title'];
            $size = $rows['Medium'];
            $medium = $rows['Size'];
            echo '<td class="paintings_gallery"><a href="show.php?ID='.$sub.'" rel="lightbox" class="paints"><img class="images" src="show.php?Paint_ID='.$rows['Paint_ID'].'" width="150" alt="Paintings" />'.$title.'</br>'.$medium.'</br>'.$size.'</a></td>';

to be honest, my code is working perfectly fine, the only problem is i cant display all the image regarding on their 'Paint_ID for example

i click the artist name 'Artist' which contain 4 paintings with a paint_id = 4, my webpage displays 4 images but all images only show the 1st image in paint#4, hope you guys get my point. Thanks in advance.
Posts: 2
Joined: 23. September 2011 16:31

help me to on how to display images from database

Postby gabyap1390 » 23. September 2011 16:39

hi guys, i've tried another set of codes to display images. but this time its not BLOB method.

here's my code:

first is the process on how i upload the photos

Code: Select all
<form enctype="multipart/form-data" action="upload.php" method="POST">
 Name: <input type="text" name="name"><br>
 E-mail: <input type="text" name = "email"><br>
 Phone: <input type="text" name = "phone"><br>
 Photo: <input type="file" name="photo"><br>
 <input type="submit" value="Add">
 //This is the directory where images will be saved
 $target = "paintings/";
 $target = $target . basename( $_FILES['photo']['name']);
 //This gets all the other information from the form
 // Connects to your Database
require_once 'conff.php';
 //Writes the information to the database
 $query = "INSERT INTO paintings2 VALUES ('', '".$name."', '".$email."', '".$phone."', '".$pic."')";
 //Writes the photo to the server
 if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
 //Tells you if its all ok
 echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
 else {
 //Gives and error if its not
 echo "Sorry, there was a problem uploading your file.";

second is how i retrieve it

Code: Select all
require_once 'conff.php';
 //Retrieves data from MySQL
 $data = mysql_query("SELECT * FROM paintings2") or die(mysql_error());

//Puts it into an array
while($info = mysql_fetch_array( $data )) { //Outputs the image and other data
   //echo "<img src='Bluematiz/paintings/".$info['photo'] ."'> <br>";
   echo "<img src='Bluematiz/paintings/".$info['photo']."'></br>";
   Echo "<b>Name:</b> ".$info['name'] . "<br> ";
   Echo "<b>Email:</b> ".$info['email'] . " <br>";
   Echo "<b>Phone:</b> ".$info['phone'] . " <hr>";

the problem here is i cant see my image, i think its broken or something. Thanks guys in advance, ive been working on these in two days but still cant figure things out.
Posts: 2
Joined: 23. September 2011 16:31

Return to PHP

Who is online

Users browsing this forum: No registered users and 1 guest