Results 1 to 4 of 4

Thread: [RESOLVED] PHP Displaying images that are stored in a blob field

  1. #1
    Hyperactive Member louvelle's Avatar
    Join Date
    Jun 08
    Posts
    464

    Resolved [RESOLVED] PHP Displaying images that are stored in a blob field

    This is my code and somehow it works.
    Code:
    <table border="1">
    <?php
    
    	mysql_connect("localhost", "root") or die("Cannot connect to database: ".mysql_error());
    	mysql_select_db("db_pcaccess") or die("Cannot connect to database: ".mysql_error());
    	
    	$category = "Monitor";
    	$query = mysql_query("SELECT * FROM tbl_products WHERE pcategory='".$category."'");
    	
    	$a = 1;
    	while ($row = mysql_fetch_array($query))
    	{
    		if($a <= 3){ //number of cells in a row
    			echo '<td>'.$row['pimage'].'</td>';
    			$a++;
    		}
    		else{
    			echo '</tr>\n<td>'.'<td>'.$row['pimage'].'</td>';
    			$a = 1;
    		}
    	}
    	echo '</tr>';
    ?>
    </table>
    The problem is i don't know where to put this code so that it tells the browser that the file would be a jpg file.
    Code:
    header('Content-type: image/jpg');
    I tried displaying a single image without the table and it works. But when I add the table code and the loop, it doesn't display the images that I've put in the database. Please help. I'm only a beginner in PHP.

    Manny Pacquiao once posted in his twitter:
    It doesn't matter if the grammar is wrong, what matter is that you get the message

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 08
    Location
    Trivandrum, Kerala, India
    Posts
    7,557

    Re: PHP Displaying images that are stored in a blob field

    Check this: http://stackoverflow.com/questions/5...n-a-mysql-blob

    One more thing, avoid using mysql_* functions for db interaction. Instead use, mysqli or PDO.


    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD Athlon X2 5200+, ASUS Motherboard, 2 GB RAM, 400 GB HDD, Nvidia 8600 GT 512MB, 19.5" TFT(Wide), Creative 5.1 Home Theater

    Social Group: VBForums - Developers from India

    Skills: PHP, MySQL, jQuery, VB.Net, VB6, Photoshop...

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 02
    Location
    Bristol, UK
    Posts
    35,548

    Re: PHP Displaying images that are stored in a blob field

    Thread moved from the 'XML, HTML, Javascript, Web and CSS' forum to the 'PHP' forum

    (thanks as always for letting us know akhileshbc )

  4. #4
    Hyperactive Member louvelle's Avatar
    Join Date
    Jun 08
    Posts
    464

    Re: PHP Displaying images that are stored in a blob field

    Thanks for the reply akhileshbc.
    I'll check the link that you gave me.

    Sorry for posting in the wrong section.

    Manny Pacquiao once posted in his twitter:
    It doesn't matter if the grammar is wrong, what matter is that you get the message

Posting Permissions

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