 |
|
อันนี้เป็นหน้าหลักคับ
Code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//TH"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="th" lang="th">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=tis-620" />
<title>ระบบค้นหานักเรียน</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript" src="js/script.js"></script>
</head>
<body>
<div>
<form id="searchform">
<div>กรุณากรอกข้อมูล<input type="text" size="30" value="" id="inputString" onkeyup="lookup(this.value);" />
</div>
<div id="suggestions"></div>
</form>
</div>
</body>
</html>
อันนี้หน้าที่ดึงข้อมูลครับ
Code
<p id="searchresults">
<?php
// PHP5 Implementation - uses MySQLi.
// mysqli('localhost', 'yourUsername', 'yourPassword', 'yourDatabase');
$db = new mysqli('localhost', 'root', '1234', 'eoffice');
if(!$db) {
// Show error if we cannot connect.
echo 'ERROR: Could not connect to the database.';
} else {
// Is there a posted query string?
if(isset($_POST['queryString'])) {
$queryString = $db->real_escape_string($_POST['queryString']);
// Is the string length greater than 0?
if(strlen($queryString) >0) {
$query = $db->query("SELECT * FROM i_student WHERE stid LIKE '%" . $queryString . "%' ORDER BY stid LIMIT 8");
mysql_query("SET NAMES TIS620");
mysql_query("SET character_set_results=tis-620");
mysql_query("SET character_set_client=tis-620");
mysql_query("SET character_set_connection=tis-620");
if($query) {
// While there are results loop through them - fetching an Object.
// Store the category id
$stid = 0;
while ($result = $query ->fetch_object()) {
if($result->stid != $stid) { // check if the category changed
echo '<span class="category">'.$result->firstname.'</span>';
$stid = $result->stid;
}
//echo '<a href="'.$result->url.'">';
//echo '<img src="search_images/'.$result->img.'" alt="" />';
$firstname = $result->firstname;
if(strlen($firstname) > 35) {
$firstname = substr($firstname, 0, 35) . "...";
}
echo '<span class="searchheading">'.$firstname.'</span>';
$description = $result->firstname;
if(strlen($description) > 80) {
$description = substr($description, 0, 80) . "...";
}
echo '<span>'.$description.'</span></a>';
}
echo '<span class="seperator">'.$firstname.'</span><br class="break" />';
} else {
echo 'ERROR: There was a problem with the query.';
}
} else {
// Dont do anything.
} // There is a queryString.
} else {
echo 'There should be no direct access to this script!';
}
}
?>
</p>
ส่วนอันนี้เป็น JS
Code
[code]/*
* Author: Marco Kuiper (http://www.marcofolio.net/)
*/
google.load("jquery", "1.3.1");
google.setOnLoadCallback(function()
{
// Safely inject CSS3 and give the search results a shadow
var cssObj = { 'box-shadow' : '#888 5px 10px 10px', // Added when CSS3 is standard
'-webkit-box-shadow' : '#888 5px 10px 10px', // Safari
'-moz-box-shadow' : '#888 5px 10px 10px'}; // Firefox 3.5+
$("#suggestions").css(cssObj);
// Fade out the suggestions box when not active
$("input").blur(function(){
$('#suggestions').fadeOut();
});
});
function lookup(inputString) {
if(inputString.length == 0) {
$('#suggestions').fadeOut(); // Hide the suggestions box
} else {
$.post("rpc.php", {queryString: ""+inputString+""}, function(data) { // Do an AJAX call
$('#suggestions').fadeIn(); // Show the suggestions box
$('#suggestions').html(data); // Fill the suggestions box
});
}
} [/code]
อยากรู้ว่าทำไมมันไม่อ่านภาษาไทยครับผมเวลาค้นหามันออกภาษาต่างดาวครับ
Tag : PHP, MySQL, HTML/CSS, JavaScript, Ajax
|
|
 |
 |
 |
 |
Date :
2012-10-23 00:38:55 |
By :
maisurin |
View :
1098 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |