|  | 
	                
  
    | 
	 
        ถามเกี่ยวกับ  auto  complete อยากได้แบบวน  loop ค่ะ     |  
    |  |  
 
	
		|  |  |  |  |  
		|  |  | 
          
            | อยากได้ แบบวน Loop ค่ะ  ไม่ทราบว่าต้องแก้ไขตรงไหนค่ะ  ขอคำแนะนำหน่อยค่ะ 
 Code (PHP)
 
 <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="../css/autocomplete.css"  type="text/css"/>
<script type="text/javascript" src="../js/autocomplete.js"></script>
</head>
<body>
<form action="" method="post">
<? for($i=0;$i<=5; $i++){?>
  <input type="text" name="no" id="no" />
  <input name="id" type="hidden" id="id" value="" />
<? } ?>
</form>
</body>
</html>
<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 "auto.php?q=" +encodeURIComponent(this.value);
    });
}	
make_autocom("no" ,"id");
</script>
 auto.php
 Code (PHP)
 
 <?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("conn.php");
 
$q = urldecode($_GET["q"]);
$date = date("Y-m-d");
$sql ="select * from board where no LIKE '%$q%' or no LIKE '%$q%' "; 
echo $sql;
$results = mysql_query($sql);
while ($row = mysql_fetch_array($results)) {
	$id = $row["id"]; // ฟิลที่ต้องการส่งค่ากลับ
	$name = $row["no"] ; // ฟิลที่ต้องการแสดงค่า
	$name_no = $row["no1"] ;
	// ป้องกันเครื่องหมาย '
	$name = str_replace("'", "'", $name);
	$name_no = str_replace("'", "'", $name_no);
	// กำหนดตัวหนาให้กับคำที่มีการพิมพ์
	$display_name = preg_replace("/(" . $q . ")/i", "<b>$1</b>", $name .  " <b> MVA : </b>" . $name_no . " " );
	echo "<li onselect=\"this.setText('$name  $name_no').setValue('$id');\"> $display_name </li>";
}
mysql_close();
?>
 
 
 Tag : PHP, MySQL
 
 
 |  
            |  |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2013-03-06 15:28:49 | By :
                          testone | View :
                          1021 | Reply :
                          2 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |  
		|  |  |  |  |  
  
    | 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | อย่างไงอ่ะครับ ผมก็ใช้ตัวนี้อยู๋เหมือนกัน แค่มีปัญหาที่ พอกดรูปแว่น(ค้นหา มันไม่แสดงชื่อที่เป้นภาษาไทย) แต่ถ้าพิมพ์ไทย มันแสดง auto ภาษาไทยได้ครับ แล้วที่ว่าต้องการวนลูปนี้ยังไเหรอครับ ที่ใช้อยู่ก็เป็นแบบนี้ครับ
 Code (PHP)
 
 <?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");
	mysql_query("SET NAMES UTF8");
	mysql_query("SET character_set_results=UTF8");
	mysql_query("SET character_set_client=UTF8");
	mysql_query("SET character_set_connection=UTF8");
	mb_internal_encoding('UTF-8');
	mb_http_output('UTF-8');
	mb_http_input('UTF-8');
	mb_language('uni');
	mb_regex_encoding('UTF-8');
	ob_start('mb_output_handler');
	setlocale(LC_ALL, 'th_TH');
 
$q = urldecode($_GET["q"]);
//$q= iconv('utf-8', 'tis-620', $_GET['test']);
$pagesize = 50; // จำนวนรายการที่ต้องการแสดง
$table_db=" ae_work"; // ตารางที่ต้องการค้นหา
$find_field="ae_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["ae_id"]; // ฟิลที่ต้องการส่งค่ากลับ
	$name =$row["ae_name"]; // ฟิลที่ต้องการแสดงค่า
	// ป้องกันเครื่องหมาย '
	$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();
?>
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2013-03-06 17:27:24 | By :
                            akkaneetha |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | คือต้องการให้มี  Code (PHP) 
 <form action="" method="post">
<? for($i=0;$i<=5; $i++){?>
  <input type="text" name="no" id="no" />
  <input name="id" type="hidden" id="id" value="" />
<? } ?>
 ช่องสำหรับการค้นหา หลายช่อง  ค่ะ
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2013-03-06 18:00:03 | By :
                            testone |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  |  |