|
|
|
ช่วยดูโค๊ดในการค้นหา autocomplete แบบหลาย field หน่อยค่ะ |
|
|
|
|
|
|
|
เป็นการค้นหา ข้อมูลแบบ auto ค่ะตอนนนี้หาแบบ auto เป็นแค่ field แรกค่ะอยากให้หาแบบ auto หมดเลยค่ะ รบกวนช่วยดูให้หน่อยค่ะ
Code
<link rel="stylesheet" href="css/autocomplete.css" type="text/css"/>
<script type="text/javascript" src="js/autocomplete.js"></script>
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<form method="post" action="book_code.php" >
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="line-height:30px; font-size:13px;">
<tr>
<td width="100%" valign="top" style="font-size:25px; line-height:40px; padding-top:10px;" >
<? for ($i = 1; $i <= 10; $i ) { ?>
<input type="text" name="book_name[]" id="book_name[]" size="25" style="width:400px; height:50px; font-size:40px; color:#FF0000;"/>
<? } ?>
<input name="book_id[]" type="hidden" id="book_id[]" value="" />
</td>
</tr>
</table>
</form>
<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 "777_1.php?q=" encodeURIComponent(this.value);
});
}
make_autocom("book_name[]" ,"book_id[]");
</script>
page2
Code
<?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);
require("connn.php");
$q = urldecode($_GET["q"]);
$sql ="select * from tb_book where book_name LIKE '%$q%' ";
$results = mysql_query($sql);
while ($row = mysql_fetch_array($results)) {
$id = $row["book_id"];
$name = $row["book_name"] ;
$name_no = $row["book_code"];
$name = str_replace("'", "'", $name);
$name_no = str_replace("'", "'", $name_no);
$display_name = preg_replace("/(" . $q . ")/i", "<b>$1</b>", $name . " <b> Book: </b>" . $name_no . " " );
echo "<li onselect="this.setText('$name $name_no').setValue('$id');"> $display_name </li>";
}
mysql_close();
?>
Tag : PHP
|
|
|
|
|
|
Date :
2013-06-15 16:59:34 |
By :
testone |
View :
959 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|