嗨,我已经使用3个表的mysql查询在窗体上创建了一个下拉组合框,并且工作正常,现在我要在运行此查询的下拉组合中选择一个项目时,要对数据库进行另一个查询在数据库中返回值,并返回在定义的字段中使用其他数据填充表单所需的值。
下面是我到目前为止所走的距离...

$query3 = "SELECT customers.id, customers.email, customers_customfields.customer_id, customers_customfields.field_value, orders.sign_date, orders.sub_id, orders.domain_name, orders.cust_status
FROM customers, customers_customfields, customers_orders, orders
WHERE customers_orders.order_id = orders.sub_id
AND customers.id = customers_orders.customer_id
AND customers.id = customers_customfields.customer_id
AND customers_customfields.field_id = 1";

$result = mysql_query ($query3);
echo "<select name=orders value='Select from the list provided '>";


while($drop=mysql_fetch_array($result)){

//data stored in $drop
echo "<option value=$drop[id]>$drop[sub_id]&nbsp;&nbsp;&nbsp;&nbsp;$drop[id]&nbsp;&nbsp;$drop[field_value]&nbsp;&nbsp;$drop[sign_date]&nbsp;&nbsp;$drop[domain_name]&nbsp;&nbsp;&nbsp;&nbsp;$drop[cust_status]</option>";

}
echo "</select>";

最佳答案

PHP严格来说是一种服务器端语言。如果您希望数据库中的字段为用户动态更新应用程序(而不必提交和刷新),则必须使用AJAX。

通读一些AJAX教程以了解一般想法。

同样,使用数据库抽象层(例如PDO)也是一个好主意。

它几乎在任何情况下都是有用的,允许使用准备好的语句以及其他优点。另外,请使用MySqli代替已淘汰的MySql。

Ajax教程:http://www.smashingmagazine.com/2008/10/16/50-excellent-ajax-tutorials/

PDO:http://php.net/manual/en/book.pdo.php

准备的语句:http://php.net/manual/en/pdo.prepared-statements.php

MySqli:http://php.net/manual/en/book.mysqli.php

09-30 15:46
查看更多