2014-05-25 3 views
0

양식에 텍스트 필드와 테이블이 있습니다. 우리가 텍스트 필드에 값을 넣을 경우 해당 이름은 테이블에 표시 할 필요가 : 값이 테이블에 입력이 코드를 사용하여텍스트 필드에서 테이블에 값 추가

<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> 
<center><table> 
<tr><td>no</td><td><input type="text" name="no" autofocus></td></tr> 
</table></center> 
<br> 
<br> 
<center> 
<table cellpadding="0" cellspacing="0" width="60%" border='1' bgcolor="#999999"> 
    <thead> 
    <tr> 
     <th> Element_Number</th> 

    </tr> 
    </thead> 

<?php 
if(isset($_POST['no'])) 
{ 
    $c=mysql_connect("localhost","root",""); 
    mysql_select_db("test"); 
    if(!$c) 
    { 
     echo "db prob".mysql_error(); 
    } 

    $no=$_POST['no']; 
    $qry=mysql_query("select name from opt where no='$no'"); 
    if(!$qry) 
    { 
     echo "ret".mysql_error(); 
    } 


     if(mysql_num_rows($qry)!=0) 
     { 
      $row=mysql_fetch_array($qry); 
      $name=$row['name']; 
     } 
     else 
     { 
      echo "query Invalid"; 
     } 
    echo "<td>" .$name."</td></tr>" ; 

} 
?> 

하지만 난 테이블과 자주 값을 이름을 추가 할 다음 값이

+0

의 도움으로 그것을 할 텍스트 필드에 입력 한 다음 행은 어디 폼 태그를 제출입니까? –

답변

1

아약스

<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> 
<center> 
<table> 
<tr><td>no</td><td><input type="text" name="no" autofocus></td></tr> 
<tr><input type="button" name="submit" value="submit"></tr> 
</table></center> 
</form> 
<br> 
<br> 
<center> 
<table id="test_table" cellpadding="0" cellspacing="0" width="60%" border='1' bgcolor="#999999"> 
    <thead> 
    <tr> 
     <th> Element_Number</th> 
    </tr> 
    </thead> 
<tbody> 
</tbody> 
</table> 

<script> 

    $(document).ready(function(){ 
     $('#submit').click(function(){ 
     var no=$('[name="no"]'); 
     $.post('your_current_page_name.php',{"no":no},function(data){ 
$("#test_table> tbody").append(data); 

}); 
     }); 
     }); 
</script> 

<?php 
if(isset($_POST['no'])) 
{ 
    $c=mysql_connect("localhost","root",""); 
    mysql_select_db("test"); 
    if(!$c) 
    { 
     echo "db prob".mysql_error(); 
    } 

    $no=$_POST['no']; 
    $qry=mysql_query("select name from opt where no='$no'"); 
    if(!$qry) 
    { 
     echo "ret".mysql_error(); 
    } 


     if(mysql_num_rows($qry)!=0) 
     { 
      $row=mysql_fetch_array($qry); 
      $name=$row['name']; 
     } 
     else 
     { 
      echo "query Invalid"; 
     } 
    echo "<tr><td>" .$name."</td></tr>" ; 

} 
+0

은 동일한 출력을 표시합니다. – naju

관련 문제