doumian3780 2012-11-22 11:45
浏览 128
已采纳

需要在PHP中按钮单击数据库中的文本框中获取值

I need to get values of database in text boxes on button click using PHP and Javascript. For instance, I get values in an HTML table from a database table. I need to get the respective values in the text boxes when the user clicks on the add0 button.

Here is my code:

<form method="post" action="">
  <input type="text" name="tb1" />
  <input type="text" name="tb2" />
  <input type="submit" name="btn" value="Find" />
</form>
<?php
  include "conn.php";
  $show = "SELECT * FROM data";
  $rs = mysql_query($show) or die(mysql_error());
  $add_to_textbox = "<input type='button' name='btn' value='add0' />";
  #****results in Grid****
  echo "<table width='360px' border='1' cellpadding='2'>";
  while($row = mysql_fetch_array($rs)) {
    echo "<tr>";
    echo "<td width='130px'>$row[Name]</td>";
    echo "<td width='230px'><a href = '$row[Link]'>$row[Link]</a></td>";
    echo "<td width='130px'>$add_to_textbox</td>";
    echo "</tr>";
  }
  echo "</table>";
  #**********************
  mysql_free_result($rs);
?>

I need further code on button click.

  • 写回答

2条回答 默认 最新

  • duanne9313 2012-11-22 11:55
    关注

    imho you can use Inline edit using Ajax in Jquery

    Here is it's demo

    It will let you edit your displayed contents in the table itself..

    Update:

    <form method="post" action="">
      <input type="text" name="tb1" id="tb1" />
      <input type="text" name="tb2" id ="tb2" />
      <input type="submit" name="btn" value="Find" />
    </form>
    <?php
      include "conn.php";
      $show = "SELECT * FROM data";
      $rs = mysql_query($show) or die(mysql_error());
      $add_to_textbox = "<input type='button' name='btn' value='add0' />";
      #****results in Grid****
      echo "<table width='360px' border='1' cellpadding='2'>";
      $rowID=1;
      while($row = mysql_fetch_array($rs)) {
        echo "<tr>";
        echo "<td width='130px' id='name".$rowID."'>$row[Name]</td>";
        echo "<td width='230px' id='link".$rowID."'><a href = '$row[Link]'>$row[Link]</a></td>";
        echo "<td width='130px' onclick='txtValDisp($rowID);'>$add_to_textbox</td>";
        echo "</tr>";
        $rowID++;
      }
      echo "</table>";
      #**********************
      mysql_free_result($rs);
    ?>
    <script type="text/javascript">
    function txtValDisp(rowID){
        var linkVal = document.getElementById('link'+rowID+'').innerHTML.replace(/<\/?[^>]+(>|$)/g, "
    ");
        document.getElementById("tb1").value = document.getElementById('name'+rowID+'').innerHTML;
        document.getElementById("tb2").value = linkVal; 
        }
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)