suess0r Posted June 5, 2007 Share Posted June 5, 2007 Hi there, So i have the setup on the format I want to print all my result sets out, but I still don't know how to print the BLOB image?! I have a mediumblob setup and uploaded the images but i'm just not sure how to print them out. Here's what I gotz so far.. *Note: Where the "images/2_p4.jpg" is where I want to print the image! And it should be stored in $img $result_set = mysql_query($sql) or die("$sql FAILED because ".mysql_error()); if (mysql_num_rows($result_set) > 0){ for ($i = 0; $i < mysql_num_rows($result_set); $i++) { $ename = mysql_result($result_set, $i, "Event_Name"); $date = mysql_result($result_set, $i, "Event_Date"); $vname = mysql_result($result_set, $i, "Venue_Name"); $description = mysql_result($result_set, $i, "Event_Description"); $cost = mysql_result($result_set, $i, "Event_Cost"); $img = mysql_result($result_set, $i, "Thumb"); // on left echo' <div style="margin:9 15 0 20px "><a href="#"><img src="images/2_p4.jpg" align="left" style="margin-right:15px " alt="" border="0"></a><span style="color: #00BCD4"><br style="line-height:9px"> <span class="style4">'.$ename.' at '.$vname.'</span></span><br> '.$description.'... <br><span class="style8">VIP Exclusive Cost of: '.$cost.'</span><br> <span class="style6" style="float:right; margin: 0 20px 0 0"><a href="#"><strong>read more</strong></a></span></div><br> <br style="line-height:11px"><img src="images/1_line.gif" style="margin-left:55px " alt="" border="0" width="425"><br><br style="line-height:10px">'; } } else { echo 'Sorry, no results were found...'; } ?> Appreciate any help! Quote Link to comment https://forums.phpfreaks.com/topic/54315-echoing-my-blob-image/ Share on other sites More sharing options...
suess0r Posted June 5, 2007 Author Share Posted June 5, 2007 anyone have any ideas about printing the blob images in the database? Quote Link to comment https://forums.phpfreaks.com/topic/54315-echoing-my-blob-image/#findComment-268715 Share on other sites More sharing options...
per1os Posted June 5, 2007 Share Posted June 5, 2007 You are going to need to make a separate file to retrieve the images. IE: get_image.php?imageid=1 //getimage.php <?php if (isset($_GET['imageid'])) { $qu = mysql_query("SELECT thumb FROM table_name WHERE imageid = " . $imageid) or die(mysql_error()); $image = mysql_fetch_array($qu); header("Content-type: image/jpeg"); // unsure of what this should really be echo $image['thumb']; } ?> And than replace the images/2_p4.jpg with getimage?imageid=3 Quote Link to comment https://forums.phpfreaks.com/topic/54315-echoing-my-blob-image/#findComment-268723 Share on other sites More sharing options...
dbillings Posted June 5, 2007 Share Posted June 5, 2007 Your best bet is to have a seperate script that will build your image and link to it via a hyperlink. You need to include a header with the correct MIME type as well which I don't see in your script. <?php // Create whatever filename is convenient for you I'll pick image.php. // This will need to be saved as a seperate file // this will generate your images when you link to it. // I assume you are only using jpeg images otherwise // you will need a bit more code. IF(isset($_GET['id'])){ // Set your mysql connect code here. $id= $_GET['id']; $query="SELECT Thumb FROM img where id='$id'"; $result= mysql_query($query)or die('Error: '.mysql_error()); $image= mysql_fetch_assoc($result); //header("Content-type: image/pjpeg"); echo $image['Thumb']; mysql_close(); echo $image; } ?> Next you'll need to change your other script to retrieve a unique identifier for the image instead of the blob of the image itself. In this script I use the images id if you have one setup in mysql. Best practice is to have a seperate table for images but to each their own. <?php $result_set = mysql_query($sql) or die("$sql FAILED because ".mysql_error()); if (mysql_num_rows($result_set) > 0){ for ($i = 0; $i < mysql_num_rows($result_set); $i++) { $ename = mysql_result($result_set, $i, "Event_Name"); $date = mysql_result($result_set, $i, "Event_Date"); $vname = mysql_result($result_set, $i, "Venue_Name"); $description = mysql_result($result_set, $i, "Event_Description"); $cost = mysql_result($result_set, $i, "Event_Cost"); $img = mysql_result($result_set, $i, "id"); echo' <div style="margin:9 15 0 20px "><a href="#"><img src="images.php?id=$img" align="left" style="margin-right:15px " alt="" border="0">[/url]<span style="color: #00BCD4"><br style="line-height:9px"> <span class="style4">'.$ename.' at '.$vname.'</span></span> '.$description.'... <span class="style8">VIP Exclusive Cost of: '.$cost.'</span> <span class="style6" style="float:right; margin: 0 20px 0 0"><a href="#"><strong>read more</strong>[/url]</span></div> <br style="line-height:11px"><img src="images/1_line.gif" style="margin-left:55px " alt="" border="0" width="425"> <br style="line-height:10px">'; } } else { echo 'Sorry, no results were found...'; } ?> Good luck! Quote Link to comment https://forums.phpfreaks.com/topic/54315-echoing-my-blob-image/#findComment-268741 Share on other sites More sharing options...
suess0r Posted June 5, 2007 Author Share Posted June 5, 2007 dbillings, thanks so much... clear and well explained explanation. Everything's working great, thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/54315-echoing-my-blob-image/#findComment-268863 Share on other sites More sharing options...
dbillings Posted June 6, 2007 Share Posted June 6, 2007 Click solved on your thread. Quote Link to comment https://forums.phpfreaks.com/topic/54315-echoing-my-blob-image/#findComment-268909 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.