|
 |
|
ต้องการทำให้ textbox เป็น autocomplete โดยการดึงข้อมูลจากฐาน oracle |
|
 |
|
|
 |
 |
|
ต้องการทำให้ textbox เป็น autocomplete โดยการดึงข้อมูลจากฐาน oracle
และแสดงเป็นภาษาไทย ตาม code ด้านล่างนี่ไม่ทราบว่าผิดตรงไหน มันแค่แสดงข้อมูลทั้งหมดออกมา
แต่ยังไม่อยู่ในรูปแบบ autocomplete
Code (PHP)
<html>
<head>
<title></title>
<script type="text/javascript" src="autocomplete.js"></script>
<link rel="stylesheet" href="autocomplete.css" type="text/css"/>
<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 "data.php?q=" +encodeURIComponent(this.value);
});
}
// การใช้งาน
// make_autocom(" id ของ input ตัวที่ต้องการกำหนด "," id ของ input ตัวที่ต้องการรับค่า");
make_autocom("show_arti_topic","h_arti_id");
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<input name="show_arti_topic" type="text" id="show_arti_topic" size="50" />
<input name="h_arti_id" type="hidden" id="h_arti_id" value="" />
</form>
<script type="text/javascript">
// แทรก javascript
</script>
<?php
header("Content-type:text/html; charset=UTF-8");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// เชื่อมต่อฐานข้อมูล
include("connect.php");
$q = urldecode($_GET["q"]);
$pagesize = 50; // จำนวนรายการที่ต้องการแสดง
$table_db="article"; // ตารางที่ต้องการค้นหา
$find_field="arti_topic"; // ฟิลที่ต้องการค้นหา
$sqledu="select * from AVSREG.OFFICER";
$objParse=oci_parse($objConnect,$sqledu);
oci_execute($objParse,OCI_DEFAULT);
while($objResult = oci_fetch_array($objParse,OCI_BOTH))
{
$id = $objResult["OFFICERNAME"]; // ฟิลที่ต้องการส่งค่ากลับ
$name = ucwords( strtolower( $objResult["OFFICERNAME"] ) ); // ฟิลที่ต้องการแสดงค่า
// ป้องกันเครื่องหมาย '
$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>";
}
?>
</body>
</html>
Tag : PHP, Oracle

|
|
 |
 |
 |
 |
Date :
2012-01-14 11:26:48 |
By :
banana_bnn |
View :
1470 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
|
|

|
Load balance : Server 05
|