Jump to content

How do I display images stored in my databse???


maxves1

Recommended Posts

this is the code so far :

<?php

session_start();  // SESSION STARTED

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

 

<head>

 

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

 

<style type="text/css">

<!--

.style1 {

font-family: Arial, Helvetica, sans-serif;

font-weight: bold;

}

.style3 {font-family: Arial, Helvetica, sans-serif}

-->

</style>

<SCRIPT TYPE="text/javascript">

<!--

function popup(mylink, windowname)

{

if (! window.focus)return true;

var href;

if (typeof(mylink) == 'string')

  href=mylink;

else

  href=mylink.href;

window.open(href, windowname, 'width=400,height=200,scrollbars=yes');

return false;

}

//-->

</SCRIPT>

 

<script type="text/javascript">

<!--//

function changePage(number){

var firstNumber = 001;

var lastNumber = 999;

var content = document.getElementById('content');

var oldNumber = content.src.match(/(\d+)(?=\.)/);

var newNumber = RegExp.$1*1+number;

 

if(newNumber < firstNumber){ newNumber = lastNumber };

if(newNumber > lastNumber) { newNumber = firstNumber }; 

content.src = content.src.replace(/(\d+)(?=\.)/,newNumber);

document.getElementById('test').innerHTML = content.src;

 

}

//-->

</script>

 

<title>FITL Search Page</title></head>

<BODY>

<!-- wrap starts here -->

 

 

 

<br>

<center>

<br>

<hr align="center" size="1" width="550" color=#"99CCFF">

<hr align="center" size="1" width="550" color=#"99CCFF">

<?php

$ids=$_SESSION['id'];  // USER ID

 

echo "<font size = 4 <b>All Products   </b></font>".$ids."<br>";

?>

<hr align="center" size="1" width="550" color=#"99CCFF">

<br>

<table align='center' height="251">

<tr align='center'><td height="27">

 

 

</td></tr>

 

<tr><td height="121">

<table width="688" border=0 style="border-collapse: collapse" cellpadding="20" cellspacing="20">

<tr><td width="509">

<h3>Search Results</h3>

<table valign="top" scope="row">

<tr><td>

  <table width="549" height="239" border="0">

<tbody>

          <tr>

            <td width="121"><table width="118" border="1" cellpadding="0" cellspacing="0" align="left" valign="top">

              <tr>

                <td align="center"><a href="" STYLE="text-decoration:none"><font color="#99CCFF"> Show All </font></a>

                <br /><br />

                <a href="" STYLE="text-decoration:none"><font color="#99CCFF">Category</font></a>

                <br /><br />

                <a href="" STYLE="text-decoration:none"><font color="#99CCFF">Sub-Category</font></a></td>

              </tr>

           

            </table> 

</td><td>

<?php

 

include ('db_connect.php');  // DATABASE CONNECTION

 

{             

$keyword=$_REQUEST['T1'];

                if($keyword=="")

                  {

 

                 

                    header( 'location:http://faculty.poly.edu/~yjeanpie/search.html');

              exit();

                   

                  }

 

$sql="select * from PRODUCTS NATURAL JOIN category NATURAL JOIN SUB_CATEGORIES where PRODUCTS.prod_name like '$keyword%'";

$result=mysql_query($sql);

$rowcount=mysql_num_rows($result);

if($rowcount<1)

{

echo "Search Results not Found";

exit();

}

else

{

?>

<BR><BR>

<form enctype="multipart/form-data" action="allproducts.php" method="POST">

 

<table border = 2  cellspacing="0" cellpadding="0" align="right" valign="top">

<tr><th>Image</th><th>Category</th><th>Sub-Category</th><th>Product Name</th><th>Version</th></tr>

<?php

while($mem=mysql_fetch_array($result)) 

{

$number1=$mem['category'];

$number=$mem['prod_name'];

$number3=$mem['sub_category_name'];

$number5=$mem['prod_model_version'];

$number2=$mem['img'];

 

?>

<tr>

                                <td> <?php

$sql3="select img from PRODUCTS where img='$number2'";

 

$result3=mysql_query($sql3);

$rowcount3=mysql_num_rows($result3);

if($rowcount3<1)

{

$rate='Not found';

}

else

{

                    while($row3=mysql_fetch_array($result3))

{

$rate=$row3[0];

if (!empty($row3[0]))

  {

    // Output the MIME header

    header("Content-Type:image/jpeg");

    // Output the image

    echo $row3[0];

  }

 

}

}

?>

        <?php

if($rate!=null)

//header("Content-type: image/jpeg");

    echo '<a href="generalinfo.php"><img src="'.$rate.'"></a>';

else

echo " ";

?>

</td> <td>

<?php

$sql3="select category from category NATURAL JOIN PRODUCTS where category='$number1' and PRODUCTS.cat_id=category.cat_id";

$result3=mysql_query($sql3);

$rowcount3=mysql_num_rows($result3);

if($rowcount3<1)

{

$rate="Not found";

}

else

{

                    while($row3=mysql_fetch_array($result3))

{

$rate=$row3[0];

}

}

?>

        <?php

if($rate!=null)

echo '<center>'.$rate.'</center>';

else

echo "Available";

?></td><td>

<?php

$sql3="select sub_category_name from SUB_CATEGORIES NATURAL JOIN PRODUCTS where sub_category_name='$number3' and PRODUCTS.sub_category_id=SUB_CATEGORIES.sub_category_id";

$result3=mysql_query($sql3);

$rowcount3=mysql_num_rows($result3);

if($rowcount3<1)

{

$rate="Not found";

}

else

{

                    while($row3=mysql_fetch_array($result3))

{

$rate=$row3[0];

}

}

?>

        <?php

if($rate!=null)

echo '<center>'.$rate.'</center>';

else

echo " ";

?></td><td>

        <?php

$sql3="select  prod_name from PRODUCTS where prod_name='$number'";

$result3=mysql_query($sql3);

$rowcount3=mysql_num_rows($result3);

if($rowcount3<1)

{

$rate="Not found";

}

else

{

                    while($row3=mysql_fetch_array($result3))

{

$rate=$row3[0];

}

}

?>

        <?php

if($rate!=null)

echo '<center><a href="generalinfo.php">'.$rate.'</a></center>';

else

echo " ";

?></td>

 

                                  <td>

                                      <?php

$sql3="select  prod_model_version from PRODUCTS where prod_model_version='$number5'";

$result3=mysql_query($sql3);

$rowcount3=mysql_num_rows($result3);

if($rowcount3<1)

{

$rate="Not found";

}

else

{

                    while($row3=mysql_fetch_array($result3))

{

$rate=$row3[0];

}

}

?>

<?php

if($rate!=null)

echo "<center>".$rate."</center>";

else

echo " ";

?>

</td></tr>

<?php

}

?>

</table>

</form>

<?php

}

 

}

?></td><td>

</td>

</td>

<td width="169" style='margin-bottom:90px;>

 

 

</td>

</tr>

</table>

</td></tr>

</table>

</td>

</table>

</center>

 

 

</body>

 

</html>

the first loop is for the images , i have used "img" for that, but still it is not working, I dont know what to do to get it working,

you can see the demo at:

http://faculty.poly.edu/~yjeanpie/search.html

put in "a" in the searchbox and you will see the output, (same code) , but without images , i wonder how to fix this, any help would be appreciated

You need a separate file that gets the image data from the database.

<?php
// DB info
$query = mysql_query("SELECT * FROM `table` WHERE `image_details` = '$imageid'";
$row = mysql_fetch_array($rs);
$image= $row['image_details'];
header("Content-type: image/jpeg");
print $image;
?>
Use a GET to get the imageid, make sure to sanitise it and make your <img src=""> point to that file with the correct imageid.

You could embed the image data directly into the HTML page, take a look at this:

http://danielcamargo.com/blog/embedding-image-in-html/

 

<div class="some_image" style="width:100px; height: 100px; background: url(data:image/gif;base64,<?php echo base64_encode($image_data_gif); ?>);"></div>

You could embed the image data directly into the HTML page, take a look at this:

http://danielcamargo.com/blog/embedding-image-in-html/

 

<div class="some_image" style="width:100px; height: 100px; background: url(data:image/gif;base64,<?php echo base64_encode($image_data_gif); ?>);"></div>

 

Wow, nice dude! I always wondered if that was possible.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.