谁能帮我简化一下?我有一个用于查看表中的一堆数据的页面,该页面应该通过 GET 调用接受不同的值。我只是想瘦一点。再次,代码有效,对我来说只是意大利面条。
if(!$_REQUEST['foo']){
$bar = $_REQUEST['bar'];
if($bar=='all'||!$bar){ $stmt = "SELECT * FROM table
WHERE qty > 0 and
somedate >= \"{$start}\" and
somedate <= \"{$end}\"
ORDER BY id desc
";}
else{
$stmt = "SELECT * FROM table
WHERE qty > 0 and
somedate >= \"{$start}\" and
somedate <= \"{$end}\" and
bar = '$bar'
ORDER BY id desc
";}
}
else{
switch($_REQUEST['foo']){
case 'all':
$stmt = "SELECT * FROM table
WHERE qty > 0 and
somedate >= \"{$start}\" and
somedate <= \"{$end}\"
ORDER BY id desc";
break;
case 'open':
$stmt = "SELECT * FROM table
WHERE qty > 0 and
closd = 0 and
somedate >= \"{$start}\" and
somedate <= \"{$end}\"
ORDER BY id desc";
break;
case 'closed':
$stmt = "SELECT * FROM table
WHERE qty > 0 and
closd = 1 and
somedate >= \"{$start}\" and
somedate <= \"{$end}\"
ORDER BY id desc";
break;
}}