我在一个小网站上工作,我现在被困在一个小问题上。我已经用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;如果我回音任何变量,那么它将显示在该下拉列表中选择和张贴的值。
我的桌子结构如下:
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因此,例如,如果我选择天然气标准,1或2,单位,少于11,那么我应该得到5430返回。
现在,我面临的问题是如何在select语句中使用这些已发布的值,我知道我需要做一些类似于:
SELECT Consumption fron ConTable WHERE HeatingType LIKE heatingTypeDropdownValue AND MeterType LIKE MeterTypeDropDownValue etc etc.但我不太确定任何帮助都会感谢谢谢!
发布于 2016-04-16 15:47:08
我通过创建一个会话数组来解决这个问题:
`$_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']
https://stackoverflow.com/questions/36665725
复制相似问题