php if语句html选项值 [英] php if statement html option value
问题描述
假设您有以下html select语句
Suppose you have the following html select statement
<select>
<option value="Newest">Newest</option>
<option value="Best Sellers">Best Sellers</option>
<option value="Alphabetical">Alphabetical</option>
</select>
现在我想运行一个php if elseif语句,
Now I want to run a php if elseif statement that says,
if (option value = newest) {
// Run this
}
elseif ( option value = best sellers ) {
// Run this
}
等。但是我不知道在if elseif语句中放什么。换句话说,而不是'option value = newest'(我知道这是不正确的),我可以放在那里,如果选择最新,它将执行if语句,或者如果选择了畅销书,它将执行elseif语句?
etc. But I don't know what to put inside the if elseif statement. In other words instead of 'option value = newest' (which I know is incorrect), what can I put there so that if newest is selected it will execute the if statement, or if best sellers is selected it will execute the elseif statement?
推荐答案
给你的选择命名。
<select name="selectedValue">
<option value="Newest">Newest</option>
<option value="Best Sellers">Best Sellers</option>
<option value="Alphabetical">Alphabetical</option>
</select>
在你的PHP中,你会这样做:
in your PHP, you will do:
$ _ POST ['selectedValue'];
如果我是你,我宁愿如果有两个以上的条件。
if I were you, I would prefer a switch-case incase, there are more than 2 conditions.
示例:
switch($_POST['selectedValue']){
case 'Newest':
// do Something for Newest
break;
case 'Best Sellers':
// do Something for Best seller
break;
case 'Alphabetical':
// do Something for Alphabetical
break;
default:
// Something went wrong or form has been tampered.
}
这篇关于php if语句html选项值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!