Results 1 to 4 of 4

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

  1. #1

    Thread Starter
    Fanatic Member louvelle's Avatar
    Join Date
    Jun 2008
    Posts
    513

    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 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    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 FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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

    Thread Starter
    Fanatic Member louvelle's Avatar
    Join Date
    Jun 2008
    Posts
    513

    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
  •  



Click Here to Expand Forum to Full Width