Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Kal
    Kal is offline
    Regular Coder
    Join Date
    Dec 2005
    Posts
    309
    Thanks
    0
    Thanked 0 Times in 0 Posts

    selecting images from mysql db

    Hi

    i have a script which will upload an image into my mysql database and store it in the BLOB type, however i am having trouble trying to display this image when i call using a query.

    any help would be great.

    Code:
    <?php
    
    $id=$_GET['id'];
    
    require('database.php');
    
    $query  = "select 
    id,
    title,
    description,
    DATE_FORMAT(date_posted,'%d/%m/%Y') as date_posted,
    image
    from orb_orb.press_release 
    where id = '$id'";
    
    $result = mysql_query ($query) or die (mysql_error());
    
    if (mysql_num_rows($result)>0) 
    	
    {
    
    while($row=mysql_fetch_array($result))
    	
    {
    
    ?>
    
    <table border="0" width="100%" cellpadding="0" cellspacing="0">
    
    <tr>
    <td><strong><?php print $row['title'];?></strong></td>
    </tr>
    
    <tr>
    <td>&nbsp</td>
    </tr>
    
    <table border="0" cellpadding="0" cellspacing="0" align="right">
    
    <tr>
    <td>&nbsp</td>
    <td valign="top"><img src="/Press Release Layout/Press_Images/<?php print $row['image']; ?>" align="right"></td>
    </tr>
    
    </table>
    
    <p><?php print nl2br ($row['description']);?></p>
    
    <tr>
    <td>&nbsp</td>
    </tr>
    
    <tr>
    <td><p><b>Date Posted:&nbsp&nbsp&nbsp</b><?php print nl2br ($row['date_posted']);}}?></p></td>
    </tr>
    
    <tr>
    <td>&nbsp
    </tr>
    
    </table>

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    This is one of the reasons storing images in a DB is not always a great idea (but thats an argument for another day)

    you can't output html and image data at the same time like that , you would have to have a separate script for displaying the image and then link to that as per usual ...

    PHP Code:
    <?php /*display.php, display an image from database*/
    $query  "select image from orb_orb.press_release where id = '{$_GET['id']}'";
    $result mysql_query ($query) or die (mysql_error());

    /*assuming a jpg !!*/
    header("content-type: image/jpg");
    echo 
    $result['image'];
    ?>
    then in your main script ...
    PHP Code:
    <?
    <img src="display.php?id=<?=$id;?>" />
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •