我有这个开关,我会根据使用开关选择的动作来做某些事情。根据我的测试,当页面运行时,开关中的功能甚至没有发生。
我现在对能够运行 sortby 操作很感兴趣。当我转到页面时,开关将我置于第一种情况但不运行该功能。为什么?我如何解决它?
switch ($_GET['action']) {
case 'sortby':
sort_by($_GET['sortby']);
break;
case 'add':
resident_add($_GET['residentID']);
include('inc/modify/add.php');
break;
case 'edit':
resident_edit($_GET['residentID']);
include('inc/modify/edit.php');
break;
case 'delete':
resident_delete($_GET['residentID']);
include('inc/modify/delete.php');
break;
case 'search':
echo "";
break;
default:
resident_default($_GET['sortby']);
}
function sort_by($sortby) {
if ($sortby == "last_name") {
$sort_db_field = "Last Name";
$sort_order = "ASC";
} elseif ($sortby == "lot") {
$sort_db_field = "Lot";
$sort_order = "ASC";
} elseif ($sortby == "date_added") {
$sort_db_field = "No";
$sort_order = "DESC";
} else {
include('inc/error.php?error_code=100');
}
return $sort_db_field;
return $sort_order;
}
$data = mysqli_query($dbcon, "SELECT * FROM `residents` ORDER BY `residents`.`".$sort_db_field."` ".$sort_order."") or die(mysqli_error());