Click here to Skip to main content
14,977,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to display 4 images using PHP and MySQL database. I have to display the 4 images as rows.

I use the table cars with fields (`id_car`, `car_image1`, `car_image2`, `car_image3`, `car_image4`), with all the images being blob datatype.

$id = $_GET['id'];

$link = mysql_connect("localhost", "root", "");
$sql = "SELECT car_image1, car_image2, car_image3, car_image4 FROM cars WHERE id_car='$id'";
$result = mysql_query("$sql");

header('Content-type: image/jpeg');
echo $row['car_image1'];
echo $row['car_image2'];
echo $row['car_image3'];
echo $row['car_image4'];

I can only display 1 image and not the other images. Since I am a newbie to this technology I need help.

i believe your problem is there are not correct data at your database,

İf your uploading code is something like that;

$handle = fopen ($_FILES['avatar']['tmp_name'], "rb");
$image = fread ($handle, filesize($_FILES['avatar']['tmp_name']));
$image = mysql_real_escape_string($image);

and if you forgot to add this code: (which is for take the reading pointer back to top, since fread takes this pointer to the end you need to use it before fread use)
rewind( $handle);
adding this before reuse of fread, may help.
header('Content-type: image/jpeg');
$img1 = $row['car_image1'];
$img2 = $row['car_image2'];
$img3 = $row['car_image3'];
$img4 = $row['car_image4'];
echo "<img src="/filepath/".$img1."" hold=" />echo "><img src="/filepath/".$img2."" hold=" />echo "><img src="/filepath/".$img3."" hold=" /></pre></xml>"></img></img></img>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900