2012-05-04 5 views
1

私はajaxを使用してPHPでライブ検索を実行します。これは、タスク googleajax.php検索では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> 

と私はプレスキーの値を選択することはできません。このコードを実行する

<?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>"; 

    } 

} 
?> 

をgoogledata.phpを実行するための私のコードです。 値を選択できる用途は何ですか?

+2

yay! [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

関連する問題