Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Displaying image from msql database with search engine writting in php and ajax

Image Displaying error innerHTML ajax

  • Please log in to reply
No replies to this topic

#1 Samasi

Samasi

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts
  • Programming Language:C#, ActionScript
  • Learning:C++, PHP, Assembly

Posted 02 September 2012 - 01:23 AM

Hello everyone, am writting a project displaying image from msql database through a search engine build with php, ajax - but the image is not displaying properly.
Please can any help me and i promise i will be grateful.

//Database


-- phpMyAdmin SQL Dump
--
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Aug 29, 2012 at 02:20 AM
-- Server version: 5.5.24
-- PHP Version: 5.4.3
--
-- Database: `sii`
--

-- --------------------------------------------------------


CREATE DATABASE `sii`;

//Creating table


-- phpMyAdmin SQL Dump
--
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Aug 29, 2012 at 02:20 AM
-- Server version: 5.5.24
-- PHP Version: 5.4.3
--
-- Database: `sii`
--

-- --------------------------------------------------------


--
-- Table structure for table `check_records`
--

CREATE TABLE `check_records` (
`id` int(10) NOT NULL auto_increment,
`name` varchar(200) default NULL,
`check_in_no` int(10) default '0',
`check_out_no` int(10) default NULL,
`check_date` date default NULL,
`image` blob NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=68 ;







INSERT INTO `click_records` VALUES (1, 'acting', '57', '1', 1, '77', '2007-07-31');
INSERT INTO `click_records` VALUES (2, 'art', '57', '1', 1, '37', '2007-07-31');
INSERT INTO `click_records` VALUES (3, 'art', '57', '1', 1, '18', '2007-09-22');
INSERT INTO `click_records` VALUES (4, 'acting', '57', '1', 1, '43', '2007-09-21');
INSERT INTO `click_records` VALUES (5, 'art', '57', '1', 1, '25', '2007-07-31');
INSERT INTO `click_records` VALUES (6, 'out', '51', '11', 52, '18', '2007-09-27');
INSERT INTO `click_records` VALUES (7, 'out', '51', '11', 52, '98', '2007-09-27');
INSERT INTO `click_records` VALUES (8, 'out', '51', '11', 52, '68', '2007-09-27');
INSERT INTO `click_records` VALUES (9, 'out', '51', '11', 52, '12', '2007-09-27');
INSERT INTO `click_records` VALUES (10, 'are', '51', '11', 52, '19', '2007-09-27');

//ajax.js


subject_id = '';
function handleHttpResponse() {
if (http.readyState == 4) {
if (subject_id != '') {
document.getElementById(subject_id).innerHTML = http.responseText;
}
}
}
function getHTTPObject() {
var xmlhttp;
/*@cc_on
@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@else
xmlhttp = false;
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = false;
}
}
return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object


//connection.php


<?php
$conn = mysql_connect("localhost","root","") or die("could not connect to server");
mysql_select_db("sii",$conn) or die("could not connect to database");
?>

//my search page
<html>
<head>
<title>search</title>
<script type="text/javascript" src="ajax.js"></script>
<script type="text/javascript">

function getScriptPage(div_id,content_id,get_count)
{
subject_id = div_id;
content = document.getElementById(content_id).value;
http.open("GET", "script_page.php?content=" + escape(content)+"&count="+get_count, true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}

</script>
</head>

<body>
<div class="ajax-div">
<div class="input-div"><b>
Enter Search Name here :
</b><input type="text" id="text_content" size="40" onkeyup="getScriptPage('count_display','text_content','1')">
<input type="button" class="button" value="Search" onmouseup="getScriptPage('output_div','text_content','0')">
<div id="count_display">

</div>
</div>
<div class="output-div-container">
<div id="output_div">
</div>
</div>
</form>
</div>
</body>
</html>

//script_page.php

<?php
include('conn.php');

$strlen = strlen($_GET['content']);
$display_count = $_GET['count'];

$select = "select * from check_records where name like '%".$_GET['content']."%'";
$res = mysql_query($select);
$rec_count = mysql_num_rows($res);
if($display_count)
{
echo "There are <font color='red' size='3'>".$rec_count."</font> matching records found.Click Search to view result(s).";
}
else
{
?>
<center>
<table class="sofT" cellspacing="0" border="1">
<tr>
<td colspan="5" class="phed" align="center"><font color='blue' size='3'>Search Result(s)</font></td>
</tr>
<tr>
<td class='phed'>Id</td>
<td class='phed'>Name</td>
<td class='phed'>Check_In_No.</td>
<td class='phed'>Check_Out_No.</td>
<td class='phed'>Date</td>
<td class='phed'>Image</td>
</tr>
<?php
if($rec_count > 0)
{
while($data=mysql_fetch_array($res))
{
echo "<tr>
<td class='sup'>".$data['id']."</td>
<td class='sup'>".$data['name']."</td>
<td class='sup'>".$data['check_in_no']."</td>
<td class='sup'>".$data['check_out_no']."</td>
<td class='sup'>".$data['check_date']."</td>
<td class='sup'>".$data['image']."</td>

</tr>";
}
}
else
echo '<td colspan="5" align="center"><FONT SIZE="2" COLOR="red">No matching name found....!</FONT></td>';
}
?>
</center>


// This is how the image is displaying>>>>
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download