|
 |
|
autocomplete ขึ้นแต่ ช่องว่างๆ ของ combobox ผลการค้นหา |
|
 |
|
|
 |
 |
|
ผลการค้นหา

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 :
1453 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<script type="text/javascript" src="autocomplete.js"></script>
<link rel="stylesheet" href="autocomplete.css" type="text/css"/>
.ให้โหลดจากไหนครับ 2 ไฟล์นี้
|
 |
 |
 |
 |
Date :
2011-04-17 17:01:11 |
By :
โต้ง |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วยด้วยคร้าบบบบ เป็นเหมือนกัน จะเป็นพระคุณอย่างสูง
|
 |
 |
 |
 |
Date :
2011-05-28 15:40:48 |
By :
คนไม่มีความรุ้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมได้แล้วครับ ฮิๆๆๆ พอดีมีมือดีไปแก้ไฟล์ autocomplete.css
-------
color: #111; float: center; padding-left: 2em;
เป็น
color: #111; float: right; padding-left: 2em; ก็เลยผิด li ยาวมาก จนไม่เห็นข้อมูล เพราะ li ลอยอยู่เมื่อกำหนด
ส่วนที่ถามด้านบนนะครับ
1. ต้องไปลองตรวจสอบคิวรี่ว่า ถูกต้องแล้วหรือไม่ และฟิวที่ดึงมาแสดงใน li ถูกต้องหรือเปล่า
2. ไปตรวจสอบดังกรณีผมว่าด้วยนะครับ เส้นผมบังภูเขาจริงๆ ไล่โปรแกรมซะตาลาย
|
 |
 |
 |
 |
Date :
2011-05-28 16:50:11 |
By :
ผู้อ่อนหัด |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองคิวรี่ง่ายๆที่ไม่ซับซ้อนนะครับ จะได้หาสาเหตุว่าเกิดจากอะไร ค่อยไปไล่แก้โปรแกรมครับ
|
 |
 |
 |
 |
Date :
2011-05-28 16:51:42 |
By :
ผู้อ่อนหัด |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|