我正在一个小型网站上工作,我目前只是处理一个小问题。 我已经创建了一组以HTML格式填充的下拉框,例如:
<select name="heatingType" id="heatingType" required>
<option value="" disabled selected>Select Your Option</option>
<option value = "Gas">Gas</option>
<option value = "Electricity">Electricity</option>
<option value = "Other">Other</option>
</select>
我可以在表单发布/提交后将值存储在变量中,这些存储在我的Controller类中,例如:
$newCalc = new ConCalc();
// instantiate drawing tool
$draw = new DrawTool();
// parse (render) appliance view
$renderedView = $draw->render('../View/calculator.php', array('calcvalues' => $newCalc->getValues()));
if(isset($_POST['btn-calcCon'])){
$heatType = $_POST['heatingType'];
$meterType = $_POST['meterType'];
$bedrooms = $_POST['noBedrooms'];
$house = $_POST['houseType'];
$age = $_POST['houseAge'];
echo $heatType;
echo $meterType;
echo $bedrooms;
echo $house;
echo $age;
}
echo $renderedView;
如果我回显任何varibales,那么它将显示在该下拉列表中选择并发布的值。
我的表格结构如下:
HeatingType MeterType Bedrooms HouseType HouseAge Consumption
Gas Standard 1 or 2 Flat Less than 11 years 5430
Gas Standard 1 or 2 Flat More than 11 years 7270
因此,例如,如果我选择Gas,Standard,1或2,Flat和Less 11,那么我应该返回5430.
现在我遇到的问题是如何在select语句中使用这些发布的值, 我知道我需要做一些事情:
SELECT Consumption fron ConTable WHERE HeatingType LIKE heatingTypeDropdownValue AND MeterType LIKE MeterTypeDropDownValue etc etc.
但我不完全确定 任何帮助将不胜感激 谢谢!
答案 0 :(得分:0)
我通过创建会话数组来解决它:
`$_SESSION['post-data'] = $_POST;
$_SESSION['post-data']['heatingType'];
$_SESSION['post-data']['meterType'];
$_SESSION['post-data']['noBedrooms'];
$_SESSION['post-data']['houseType'];
$_SESSION['post-data']['houseAge'];`
然后在where子句中使用$_SESSION['post-data']['heatingType']