我有这样的表格:
<form method='post' name='form_filter' >
Filter By:
<select name ="select_name">
<option>...</option>
<option value = "plowest">Price Lowest</option>
<option value = "phighest">Price Highest</option>
<option value ="endingsoon">Ending Soon</option>
<option value = "newlylisted">Newly Listed</option>
</select>
<input type='submit' value = 'Filter'>
</form>
然后在php中我这样做。例如,如果用户选择价格最低,我运行某个查询。如果他选择Price Highest,我选择另一个查询,依此类推。 我的PHP代码:
if(isset($_POST['value'])) {
echo "HELLO";
if($_POST['value'] == 'plowest'){
echo($_POST['value']);
$query = "select *from(Select ROW_NUMBER() OVER(ORDER BY NAME ASC) as rn, $computerUserName.items.* FROM $computerUserName.items) where rn between $offset and $variable";
}
}
else{
$query = "select * from(Select ROW_NUMBER() OVER() as rn, $computerUserName.items.* FROM $computerUserName.items) where rn between $offset and $variable";
}
$stmt = db2_prepare($connection, $query);
$result = db2_execute($stmt);
但出于某种原因,如果我选择最低价格(价值最低),它仍会查询其他。
答案 0 :(得分:0)
应该是:
if(isset($_POST['select_name'])) {
echo($_POST['select_name']);
if($_POST['select_name'] == 'plowest'){
$query = "select *from(Select ROW_NUMBER() OVER(ORDER BY NAME ASC) as rn, $computerUserName.items.* FROM $computerUserName.items) where rn between $offset and $variable";
}
else{
$query = "select * from(Select ROW_NUMBER() OVER() as rn, $computerUserName.items.* FROM $computerUserName.items) where rn between $offset and $variable";
}
$stmt = db2_prepare($connection, $query);
$result = db2_execute($stmt);
}