我让 PHP 填充了一个下拉框,我希望它也填充同一个表中的两个只读文本框 [英] I have PHP populating a Dropdown box, and I want it to also populate two read only Text boxs from the same Table

查看:33
本文介绍了我让 PHP 填充了一个下拉框,我希望它也填充同一个表中的两个只读文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 Parts 的表(PartID、PartName、Cost),我让 PHP 填充了一个带有 PartID 的下拉框.我希望当用户选择部件 ID 时,它会使用部件名称填充一个文本框,并使用部件的成本填充另一个框.
如果有帮助的话,这就是我的下拉框代码的样子:)

I have a table called Parts, (PartID, PartName, Cost) and I have PHP populating a Drop down box with the PartID's. I want it to when a user selects a Part ID, it populates one text box with the Part's name and the other box, with the Part's cost.
Here's what my Code look's like for the drop down box if it helps any :)

$sql = "SELECT PartID FROM Parts WHERE PartID LIKE 'C0%'";
$result = mysql_query($sql);

echo "<select name='PartID'>";

while ($row = mysql_fetch_array($result)) 
{
echo "<option value='" . $row['PartID'] . "'>" . $row['PartID'] . "</option>";
}
echo "</select>";

推荐答案

您必须通过简单的 POST 或 AJAX POST POST 来检索值

You'll have to POST back to retrieve the values, either with a simple POST or an AJAX POST

if (!empty($_POST)) {

$partid = $_GET["PartID"];

$sql = "SELECT * FROM Parts WHERE PartID = '$partid'";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);

$part_name = $row ["PartName"];
$part_cost = $row ["PartCost"];
}

$sql = "SELECT PartID FROM Parts WHERE PartID LIKE 'C0%'";
$result = mysql_query($sql);

echo "<select name='PartID' onchange='document.getElementById(\'form1\').submit();'>";

while ($row = mysql_fetch_array($result)) 
{
echo "<option value='" . $row['PartID'] . "'>" . $row['PartID'] . "</option>";
}
echo "</select>";

echo "<input type='text' value='$part_name' />";
echo "<input type='text' value='$part_cost' />";

这篇关于我让 PHP 填充了一个下拉框,我希望它也填充同一个表中的两个只读文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆