我的WordPress安装中有一个表,它存储了很多数据。 我有一个 php 文件,可以在表上运行查询并返回经过良好过滤的行选择。我的wordpress页面上有一个表单,允许用户选择与mysql查询变量相对应的各种值。 如何让 php 文件使用表单中选择的值?
我的表单使用以下内容:
<input type="text" name="max_price" />
<input type="text" name="loan_fraction" />
<input type="text" name="interest_rate" />
<input type="text" list="state" />
我真的不知道我需要什么样的提交操作,但我希望它将这些值传递给我的 php,它使用它们如下:
$values = mysql_query("select
b.listing, b.bed, b.bath, b.type, b.address, b.postcode, b.state, b.price, avg_rent
from
buy_items b
join
(SELECT
bed, bath, type, suburb, postcode, AVG(price) as avg_rent
FROM
rent_items
GROUP BY bed, bath , type , suburb , postcode) a ON a.bed = b.bed and a.bath = b.bath
and a.suburb = b.suburb
and a.postcode = b.postcode
and a.type = b.type
where
(b.price * some_number) < a.avg_rent
and b.price > 50000
and price < max_price
and b.state = state");
其中some_number是loan_fraction和interest_rate的函数。
谢谢:)
只需将操作设置为指向 php 文件,并将字段名称分配给 php 中的变量似乎有效:
在 HTML 中:
<td>
<form id="buy_prop" action="http://****_data.php" method="post">How much are you willing to spend?
</td>
<td>
<input type="text" name="max_price" id="max_price">
</td>
在 PHP 中
$max_price = $_POST["max_price"];
$loan_fraction = $_POST["loan_fraction"];
etc etc