you need a *seperate* script that outputs the image data only (+ relevant 
headers)
and then you refer to that script (passing it a suitable parameter so it knows
which image to output) in the src attribute of an IMG tag.

you seem to be trying to output image data and html in a single request, which
won't work (well actually there is a way to embed the raw image data directly in
the html but AFAICR, but that's somewhat too tricky to cover right now given 
that
your still trying to grok the basics of this - no offence intended)

or have I misunderstood your question?

David Giragosian wrote:
> Good Afternoon All,
> 
> The recent threads about images got me to finally experiment with storing
> into and retrieving/displaying images from a database.
> Uploading and retrieval is fine, I'm just a bit uncertain about creating the
> dynamic display part.
> 
> // getting the data out of the db
> $imageCountinDB = 0;
> $selectedData = @mysql_query("select title, imagedata from pictures order by
> pid desc");
> while ( $row = @mysql_fetch_assoc($selectedData )) {
>         $title[] = htmlentities( $row['title'] );
>         $imageBytes[] = htmlentities( $row['imagedata'] );
>         $imageCountinDB++;
> }
> 
> // creating the an html table with one img tag per cell
> if ( IsSet( $_GET['im'] ) && $imageCountInDB > 0 ) {
>         $imageOutputStr = "<table><tr>";
>         for ( $i = 0; $i < $imageCountinDB; $i++ ) {
>                 $setID = $i + 1;
>                 $imageOutputStr .= "<td><img src=?im=$setID
> width=300></td>";
>                 if ( $setID % 3 == 0 && $imageCountinDB > $setID ) {
>                         $imageOutputStr .= "</tr><tr>\n";
>                 }
>         }
>  $imageOutputStr .= "</tr></table>";
> }
> 
> // associating the image data with the img tags
> switch ($_GET['im']) {
>    case 1: header("Content-type: image/jpeg");
>        print $bytes[0];
>        exit ();
>        break;
>    case 2: header("Content-type: image/jpeg");
>        print $bytes[1];
>        exit ();
>        break;
> 
>      (snip)
> }
> 
> <html>
> <body>
> 
> <?php echo $imageOutputStr; ?>
> 
> </body>
> </html>
> 
> 
> The question is, with all this happening in one page, is it possible to do
> the last bit dynamically?
> 
> BTW, the core of the above was nicked from
> http://www.wellho.net/solutions/php-example-php-form-image-upload-store-in-mysql-database-retreive.html
> 
> Thanks very much for reading this long post.
> 
> David
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to