|
 |
|
ทำยังไงถึงจะ select autocomplete ได้มากกว่า 2 อักษร |
|
 |
|
|
 |
 |
|
ทำยังไงถึงจะ select autocomplete ได้มากกว่า 2 ตัว ตามภาพคับ ใส่ตัวที่ 3ไปไม่ขึ้นลิสข้อมูลในฐานข้อมูลออกมาเลยนะคับทั้งที่ใส่อักษรที่มีในฐานข้อมูล
ใส่2ตัว

ใส่3 ตัว

Code
<?php
function fuzzy( $qa, $column, $s ) {
$result = "";
$lastLocate = "0";
for ($i = 0; $i < count($qa); $i++) {
$locate = "";
for ($j = 0; $j <= $i; $j++)
$locate = "LOCATE('$qa[$j]', $column, $lastLocate + 1)";
$lastLocate = $locate;
$result .= " $locate $s ";
}
return substr($result, 0, strlen( $result ) - strlen( $s ) - 1);
}
include("config.php");
mysql_query("SET NAMES UTF8");
$q = $_GET["q"];
$page_size = 25;
$qa = str_split($q);
$where = fuzzy( $qa, "Names", "> 0 AND" );
$order_by = fuzzy( $qa, "Names", "," );
$sql = "SELECT * FROM applymember WHERE $where ORDER BY $order_by, Names LIMIT $page_size";
$results = mysql_query($sql);
while ($row = mysql_fetch_array($results)) {
$IDMember = $row["IDMember"];
$Names = $row["Names"];
echo "<li onselect=\" this.setText('$Names').setValue('$IDMember'); \"><span>$IDMember</span>\n\t$Names\n</li>\n";
}
mysql_close();
?>
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2009-12-01 13:33:39 |
By :
gofgof |
View :
1175 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2009-12-01 13:43:59 |
By :
natik |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
- ลอง echo $_GET["q"] มาดูยังครับว่ามันส่งมาครบเปล่า
- ลอง echo $where มาดูยังครับว่า เขียนถูกเปล่า
- ลองเปลี่ยนจากการใช้ LOCATE เป็น LIKE ดูครับอาจแก้ได้
|
 |
 |
 |
 |
Date :
2009-12-01 14:06:43 |
By :
xbeginner01 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|