已关闭。此问题需要details or clarity。当前不接受答案。
**想要改进此问题?**添加详细信息并通过editing this post阐明问题。
昨天关门了。
Improve this question
Helo,我如何做得更好这段代码:例如$lanyear
具有查询中的值或者$lanterm
也具有查询中的值以及其它参数
if ($lanyear == "" && $lanterm == "10" && $level == "" && $class == "") {
$sql = "SELECT $field from `$table`";
} else if ($lanyear != "" && $lanterm == "10" && $level == "" && $class == "") {
$sql = "SELECT $field from `$table` WHERE tyear='$lanyear'";
} else if ($lanyear == "" && $lanterm != "10" && $level == "" && $class == "") {
$sql = "SELECT $field from `$table` WHERE term='$lanterm'";
} else if ($lanyear == "" && $lanterm == "10" && $level != "" && $class == "") {
$sql = "SELECT $field from `$table` WHERE levelnum='$level'";
} else if ($lanyear == "" && $lanterm == "10" && $level == "" && $class != "") {
$sql = "SELECT $field from `$table` WHERE classcode='$class'";
} else if ($lanyear != "" && $lanterm != "10" && $level == "" && $class == "") {
$sql = "SELECT $field from `$table` WHERE tyear='$lanyear' AND term='$lanterm'";
} else if ($lanyear != "" && $lanterm == "10" && $level != "" && $class == "") {
$sql = "SELECT $field from `$table` WHERE tyear='$lanyear' AND levelnum='$level'";
} else if ($lanyear != "" && $lanterm == "10" && $level == "" && $class != "") {
$sql = "SELECT $field from `$table` WHERE tyear='$lanyear' AND classcode='$class'";
} else if ($lanyear == "" && $lanterm != "10" && $level != "" && $class == "") {
$sql = "SELECT $field from `$table` WHERE term='$lanterm' AND levelnum='$level'";
} else if ($lanyear == "" && $lanterm != "10" && $level == "" && $class != "") {
$sql = "SELECT $field from `$table` WHERE term='$lanterm' AND classcode='$class'";
} else if ($lanyear == "" && $lanterm == "10" && $level != "" && $class != "") {
$sql = "SELECT $field from `$table` WHERE levelnum='$level' AND classcode='$class'";
} else if ($lanyear != "" && $lanterm != "10" && $level != "" && $class == "") {
$sql = "SELECT $field from `$table` WHERE tyear='$lanyear' AND term='$lanterm' AND levelnum='$level'";
} else if ($lanyear == "" && $lanterm != "10" && $level != "" && $class != "") {
$sql = "SELECT $field from `$table` WHERE term='$lanterm' AND levelnum='$level' AND classcode='$class'";
} else if ($lanyear != "" && $lanterm != "10" && $level != "" && $class != "") {
$sql = "SELECT $field from `$table` WHERE tyear='$lanyear' AND term='$lanterm' AND levelnum='$level' AND classcode='$class'";
}
用条件“如果”可以吗?
请帮帮我。
1条答案
按热度按时间ljsrvy3e1#
如果这是PHP,你可以这样做: