2012-05-04 3 views
1

나는 ajax를 사용하여 PHP에서 실시간 검색을 수행합니다. 이것은 내가 키를 눌러에 대한 값을 선택할 수 없습니다이 코드를 수행 작업 googleajax.php에게For Ajax를 사용하는 PHP에서

<?php 

    $id=$_GET['id']; 
    if(isset($_POST['submit'])) 
    { 
     $temp=$_POST['name'];echo $temp; 
    } 
?> 
<html> 
<head> 
<script language="javascript" type="text/javascript"> 
function getXMLHTTP() { //function to return the xml http object 
     var xmlhttp=false; 
     try{ 
      xmlhttp=new XMLHttpRequest(); 
     } 
     catch(e) {  
      try{    
       xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); 
      } 
      catch(e){ 
       try{ 
       xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
       } 
       catch(e){ 
        xmlhttp=false; 
       } 
      } 
     } 

     return xmlhttp; 
    } 

    function getValue(id) 
    {  


     var strURL="googledata.php?id="+id; 
     var req = getXMLHTTP(); 

     if (req) { 

      req.onreadystatechange = function() { 
       if (req.readyState == 4) { 
        // only if "OK" 
        if (req.status == 200) {       
         document.getElementById('div1').innerHTML=req.responseText;      
        } else { 
         alert("There was a problem while using XMLHTTP:\n" + req.statusText); 
        } 
       }    
      }   
      req.open("GET", strURL, true); 
      req.send(null); 

     } 
    } 

</script> 
</head> 
<body> 
<form method="post"> 
     <?php 
      /*$query="Select * from tblcountry where country_id='".$id."'"; 
      echo $ 
      $res=mysql_query($res); 
      while($row=mysql_fetch_assoc($res)) 
      { 
       extract($row);*/ 
      ?> 
      <input type="text" id="name" name="name" onKeyUp="getValue(this.value)" value="<?php echo $id;?>" /> 
    <input type="submit" id="submit" name="submit" value="serch"> 

    <div id="div1" name="div1"> 

    </div> 

       <?php 
      /*<!--}-->*/ 

     ?> 
    </form> 
</body> 
</html> 

및 googledata.php

<?php 
$con=mysql_connect("localhost","root",""); 
if(!$con) 
{ 
    die("error in connection"); 
} 
else 
{ 
    mysql_select_db("hms2012",$con); 
} 
$id= $_GET['id']; 
if($id=="") 
{ 
} 
else 
{ 
    $result=mysql_query("select * from tblcountry where country_name like '$id%'"); 

    while($row=mysql_fetch_assoc($result)) 
    { 
     extract($row); 

     echo "<option value='$country_id'><a href='googleajax.php?id=$country_id'>".$country_name."</a><br></option>"; 

    } 

} 
?> 

을 수행하기위한 내 코드입니다. 값을 선택할 수있는 용도는 무엇입니까?

+2

야호! [SQL 주입!] (http://en.wikipedia.org/wiki/SQL_injection) 잘 됐네. – PeeHaa

+0

[MySQL 및 PHP (초안)] (https://gist.github.com/2362466). – PeeHaa

답변

1

<options> 태그 목록 주변에 <select></select>이 없습니다.

Ajax에 jQuery를 사용하는 방법을 살펴보아야합니다.

+0

PLZ 나에게 어떻게 키보드를 선택 하시겠습니까 데이터 – Parimal

0

무엇이 $ country_id 및 $ country_name입니까? 나는 그것을 가정으로 바꿨다. 확인해주십시오.

echo '<select name="somename">';  
    while($row=mysql_fetch_assoc($result)) 
    { 
     extract($row); 

    echo "<option value='".$row['country_id']."'><a href='googleajax.php?id=".$row['country_id']."'>".$row['country_name']."</a><br></option>"; 

    } 
    echo "</select>"; 
+0

를 제공? – Parimal

+0

에 화살표 키를 사용하여 해당 데이터를 선택하는 링크 – nithi

+0

드롭 다운 목록에서 ......... 화살표 키를 사용하여 값을 선택하는 방법 ...... – Parimal

관련 문제