Code: Select all
<img onClick="show_picture('6');" src="my_thumb.jpg">To simplify my code lets assume the following:
The 6 is the ID in the database corresponding to that image.
This is my JavaScript code (summarized for easier understanding):
Code: Select all
function show_picture(picture){
xmlHttp=GetXmlHttpObject()
var url="show_largePicture.php"
url=url+"?picture"+picture
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged() {
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
document.getElementById("Divpicture").innerHTML=xmlHttp.responseText //The "Divpicture" is a DIV inside my HTML document
}
}
function GetXmlHttpObject(){
var objXMLHttp=null
if (window.XMLHttpRequest){
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject){
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}And finally here is my php code which is supposed to display the image from the database (show_largePicture.php):
Code: Select all
<?php
$picture=$_REQUEST["picture"];
$table_name ="images";
$img_field = "b_imagedata";
$mime_field = "c_type";
include_once("../scripts/connect.php"); //This connects to MySQL database
$sqlQuery = "SELECT ".$img_field.",".$mime_field." FROM ".$table_name." WHERE i_imagen= ".$picture;
$sqlResult= mysql_query ($sqlQuery,$db);
$data = mysql_fetch_array($sqlResult);
mysql_close($db);
header("Content-Type: ".$data[$mime_field]);
echo $data[$img_field];
}
?>Any ideas on what I may be doing wrong? Is it even possible to do it?
Thanks!
P.S. I hope I posted this in the right forum section since it has three different programming languages...