 |
|
ผลการค้นหา

PHP code
Code (PHP)
<?php
header("Content-type:text/html; charset=tis-620");
// php code //
// เชื่อมต่อฐานข้อมูล
$link=mysql_connect("localhost","root","1234") or die("error".mysql_error());
mysql_select_db("tmc",$link);
mysql_query("set character set utf8");
$q = $_GET["q"];
$pagesize = 50; // จำนวนรายการที่ต้องการแสดง
$table_db="tag_main"; // ตารางที่ต้องการค้นหา
$find_field="part_name"; // ฟิลที่ต้องการค้นหา
$sql = "select * from $table_db where locate('$q', $find_field) > 0 order by locate('$q', $find_field), $find_field limit $pagesize";
$results = mysql_query($sql);
while ($row = mysql_fetch_array( $results )) {
$id = $row["arti_id"]; // ฟิลที่ต้องการส่งค่ากลับ
$name = ucwords( strtolower( $row["arti_topic"] ) ); // ฟิลที่ต้องการแสดงค่า
// ป้องกันเครื่องหมาย '
$name = str_replace("'", "'", $name);
// กำหนดตัวหนาให้กับคำที่มีการพิมพ์
$display_name = preg_replace("/(" . $q . ")/i", "<b>$1</b>", $name);
echo "<li onselect=\"this.setText('$name').setValue('$id');\">$display_name</li>";
}
mysql_close();
?>
Code
<html>
<head>
<title></title>
<script type="text/javascript" src="autocomplete.js"></script>
<link rel="stylesheet" href="autocomplete.css" type="text/css"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
<form id="form1" name="form1" method="post" action="">
<input name="show_arti_topic" type="text" id="show_arti_topic" size="50" autocomplete="off"/>
<input name="h_arti_id" type="hidden" id="h_arti_id" value="" />
</form>
</body>
<script type="text/javascript">
function make_autocom(autoObj,showObj){
var mkAutoObj=autoObj;
var mkSerValObj=showObj;
new Autocomplete(mkAutoObj, function() {
this.setValue = function(id) {
document.getElementById(mkSerValObj).value = id;
}
if ( this.isModified )
this.setValue("");
if ( this.value.length < 1 && this.isNotClick )
return ;
return "gdata.php?q=" + this.value;
});
}
// การใช้งาน
// make_autocom(" id ของ input ตัวที่ต้องการกำหนด "," id ของ input ตัวที่ต้องการรับค่า");
make_autocom("show_arti_topic","h_arti_id");
</script>
</html>
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
2010-03-19 10:32:56 |
By :
jane |
View :
1485 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |