gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 13:12:07 26 4
gpt4 key购买 nike

我需要使用 PHP 和 Javascript 在单击按钮时获取文本框中的数据库值。例如,我从数据库表中获取 HTML 表中的值。当用户单击 add0 按钮时,我需要在文本框中获取相应的值。

这是我的代码:

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

我需要更多关于按钮点击的代码。

最佳答案

恕我直言,你可以使用 Inline edit using Ajax in Jquery

<罢工>

这是demo

它可以让您在表格中编辑显示的内容。

更新:

<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, "\n");
document.getElementById("tb1").value = document.getElementById('name'+rowID+'').innerHTML;
document.getElementById("tb2").value = linkVal;
}
</script>

关于php - 需要在 PHP 中单击按钮时从数据库中获取文本框中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13512111/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com