0

I have successfully uploaded images into mysql database, but now I want to display the images alongside other row data in html page.

Thanks for your previous help.

Austin.

4
Contributors
6
Replies
9
Views
9 Years
Discussion Span
Last Post by nav33n
0

something along these lines...you'll need to tweak it to fit your script, but you should get the idea...

//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;
0

Thanks Johnsquibb for the reply,

Please see my code that I used to insert the image and other data. The image is inserted directly into the database.

<?php        
$errmsg = "";
if (! @mysql_connect("localhost","root","")) {
        $errmsg = "Cannot connect to database";
        }
@mysql_select_db("adim");

    if(isset($_REQUEST['submit']))
    {    

        $imgtype=$_FILES['uploadfile']['type'];
        $name=$_REQUEST['name'];
    $address=$_REQUEST['address'];
    $dateofbirth=$_REQUEST['dateofbirth'];



        if($imgtype=="image/jpeg" || $imgtype=="image/jpg" || $imgtype=="image/pjpeg" || $imgtype=="image/gif" || $imgtype=="image/x-png" || $imgtype=="image/bmp")
        {

            $image=$_FILES['uploadfile']['tmp_name'];
            $fp = fopen($image, 'r');
            $content = fread($fp, filesize($image));
            $content = addslashes($content);
            fclose($fp);
            $sql="insert into img_tab1 (name,image,address,dateofbirth) values ('$name','$content','$address','$dateofbirth')";
            $res=mysql_query($sql) or die (mysql_error());
       }
    }
?>

Please further suggestions to display the whole row data including the image will be appreciated.

Austin

Edited by mike_2000_17: Fixed formatting

0

You can insert in the image table the path where you have saved your picture.Then display it like:

<img src =\" ". $row['imageURL'] . "\">
//where the value of $row['imageURL'] is the path of the image like "www.domain.com/pics/pic1.jpg"
0

Its not a good idea to store images in the database. As Ryan_vietnow has mentioned, it will add on to the server load, slows down the execution of the script and takes a lot of time to display it if you have more (say 100 images ) per page!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.