Page 1 of 1

Multiple images reading from db

Posted: Wed Oct 05, 2005 8:15 am
by ATH0
Hi !

Q.

Code: Select all

Image                     Name                                Info      
1
2
3
4
5
...
This is the way i want to display my stored images, from db.
Picture, name of the picture, info with link.
All this is in the table. I have cca 100 images in db uploaded on the way that i have read the whole directory of images and save the paths to them:

Code: Select all

$encoded = chunk_split(base64_encode($file_content)); 
$sql = "INSERT INTO images SET image64='$encoded'";
The problem is how to display all images on the way i have written before ( and what happens if i add new image). Would the table make automaticly "resize"?

ATH0

Posted: Wed Oct 05, 2005 8:21 am
by feyd
Would the table make automaticly "resize"?
I have no idea what you just asked. :?

in HTML, images are sent in a separate stream for each image. Therefore you will need a script that can retrieve a single image and output its binary data making the script appear as if it was an image.. meaning you need to send content-type and content-length headers as well so the browser can correctly read the information.

Posted: Fri Oct 07, 2005 5:32 am
by ATH0
OK. I have written this a bit slappy.
Sorry my mistake. :oops:

1.) The display should be like in my last post , thats the same :-).

2.) After i have fill in the db with images, in the image64 field you have encoded stuff like this:

R0lGODlhbgBeAOYAAAYGEu7l46WutJyRi0dkeCFBYsLNyIV1cw8bPKWlpf/79tvg1sa4tGB0g0gt .....

for each image.
OK.

3.) The problem:
Im reading the image on this way:

Code: Select all

$img = $_REQUEST["img"];

    $result = mysql_query("SELECT * FROM image64 WHERE imgid=" . $img . ""); 
    
    if (!$result)
    { 
      echo("<b>Error performing query "); exit(); 
    } 

    while ($row = mysql_fetch_array($result) )
    { 
       $imgid 	           = $row["imgid"];
       $encodeddata = $row["image64"]; 
	}
mysql_close($dbclose);
echo base64_decode($encodeddata);
--------------------

And this is the way i read each image :

Code: Select all

<img src="image.php?img=1">
--------------------

Now, i want to display all those images ( all 100 ) in the table ( like described before ).
So i have to change this

Code: Select all

<table border="1" cellpadding="1" cellspacing="1">
  <tr>
    <td>Image</td>
    <td>Description</td>
  </tr>
  <?php do { ?>
  <tr>
    <td><?php echo $row_record_tbNew['image64']; ?></td>
    <td><?php echo $row_record_tbNew['desc']; ?></td>
  </tr>
  <?php } while ($row_record_tbNew = mysql_fetch_assoc($record_tbNew)); ?>
</table>
<div align="center"></div>
<?php
mysql_free_result($record_tbNew);
?>
into what ?.

p.s. i can read all records from db but i have problem with setting the img in this part.

Thnx in advance

Posted: Fri Oct 07, 2005 8:32 am
by feyd
this seems pretty straight forward to me, maybe I'm missing something but....

Code: Select all

<?php ?>
<table border="1" cellpadding="1" cellspacing="1">
  <tr>
    <td>Image</td>
    <td>Description</td>
  </tr>
  <?php do { ?>
  <tr>
    <td><img src="image.php?img=<?php echo $row_record_tbNew['id']; ?>"></td>
    <td><?php echo $row_record_tbNew['desc']; ?></td>
  </tr>
  <?php } while ($row_record_tbNew = mysql_fetch_assoc($record_tbNew)); ?>
</table>
<div align="center"></div>
<?php
mysql_free_result($record_tbNew);
?>