我已经考虑过如何使托管变得更容易/更清洁/更好(我想我的方法对服务器不友好,尽管我不确定)。
我的目的:减少(如果可能)“如果”部分。该部分检查哪些下拉框已从“空”更改(实际上是“全部”,但如果对某些东西更好,可以将其更改为空),并将其应用于仅显示满足这些条件的用户(家庭大学,主机大学,位置和/或国籍。这是我能够创建的唯一简单/基本的方式。
我有这个功能:
function get_user_listing($curauth) {
global $post;
$concat = wpu_concat_single();
// These get the values from the plugin Cimy User Extra Fields:
$homeuni=get_cimyFieldValue($curauth->ID,'homeuni');
$hostuni=get_cimyFieldValue($curauth->ID,'hostuni');
$location=get_cimyFieldValue($curauth->ID,'location');
$nationality=get_cimyFieldValue($curauth->ID,'nationality');
// These get the values from a dropdown form in the page:
$selectedhomeuni = $_POST['homeuni'];
$selectedhostuni = $_POST['hostuni'];
$selectedlocation = $_POST['location'];
$selectednationality = $_POST['nationality'];
//This is the code that has to be run every time to display every user info:
include '/home/u548205287/public_html/wp-content/themes/Trim/profilescode.php';
// I set an initial page that runs the code with no conditions because with
the form, the page would look empty until the form is submitted once:
if(is_page(806)) {return $html;}
else{
if($selectedhomeuni == "all" && $selectedhostuni == "all" && $selectedlocation == "all" && $selectednationality == "all") {return $html;} // The possibilities with each dropdown start here. If "all" (the "empty" one) is selected, nothing changes and all are displayed.
elseif($selectedhomeuni != "all" && $selectedhostuni == "all" && $selectedlocation == "all" && $selectednationality == "all") {if($homeuni==$selectedhomeuni) {return $html;}} // If any dropdown is selected, its value acts as a filter and only the users with that info are shown.
elseif($selectedhomeuni == "all" && $selectedhostuni != "all" && $selectedlocation == "all" && $selectednationality == "all") {if($hostuni==$selectedhostuni) {return $html;}}
elseif($selectedhomeuni == "all" && $selectedhostuni == "all" && $selectedlocation != "all" && $selectednationality == "all") {if($location==$selectedlocation) {return $html;}}
elseif($selectedhomeuni == "all" && $selectedhostuni == "all" && $selectedlocation == "all" && $selectednationality != "all") {if($nationality==$selectednationality) {return $html;}}
elseif($selectedhomeuni != "all" && $selectedhostuni != "all" && $selectedlocation == "all" && $selectednationality == "all") {if($homeuni==$selectedhomeuni && $hostuni==$selectedhostuni) {return $html;}}
elseif($selectedhomeuni != "all" && $selectedhostuni == "all" && $selectedlocation != "all" && $selectednationality == "all") {if($homeuni==$selectedhomeuni && $location==$selectedlocation) {return $html;}}
elseif($selectedhomeuni != "all" && $selectedhostuni == "all" && $selectedlocation == "all" && $selectednationality != "all") {if($homeuni==$selectedhomeuni && $nationality==$selectednationality) {return $html;}}
elseif($selectedhomeuni != "all" && $selectedhostuni != "all" && $selectedlocation != "all" && $selectednationality == "all") {if($homeuni==$selectedhomeuni && $hostuni==$selectedhostuni && $location==$selectedlocation) {return $html;}}
elseif($selectedhomeuni != "all" && $selectedhostuni != "all" && $selectedlocation == "all" && $selectednationality != "all") {if($homeuni==$selectedhomeuni && $hostuni==$selectedhostuni && $nationality==$selectednationality) {return $html;}}
elseif($selectedhomeuni != "all" && $selectedhostuni == "all" && $selectedlocation != "all" && $selectednationality != "all") {if($homeuni==$selectedhomeuni && $location==$selectedlocation && $nationality==$selectednationality) {return $html;}}
elseif($selectedhomeuni != "all" && $selectedhostuni != "all" && $selectedlocation != "all" && $selectednationality != "all") {if($homeuni==$selectedhomeuni && $hostuni==$selectedhostuni && $location==$selectedlocation && $nationality==$selectednationality) {return $html;}}
elseif($selectedhomeuni == "all" && $selectedhostuni != "all" && $selectedlocation != "all" && $selectednationality == "all") {if($hostuni==$selectedhostuni && $location==$selectedlocation) {return $html;}}
elseif($selectedhomeuni == "all" && $selectedhostuni != "all" && $selectedlocation == "all" && $selectednationality != "all") {if($hostuni==$selectedhostuni && $nationality==$selectednationality) {return $html;}}
elseif($selectedhomeuni == "all" && $selectedhostuni != "all" && $selectedlocation != "all" && $selectednationality != "all") {if($hostuni==$selectedhostuni && $location==$selectedlocation && $nationality==$selectednationality) {return $html;}}
elseif($selectedhomeuni == "all" && $selectedhostuni == "all" && $selectedlocation != "all" && $selectednationality != "all") {if($location==$selectedlocation && $nationality==$selectednationality) {return $html;}}
}
}
我想知道是否有更好的方法来做所有的如果。我确定有。谢谢 :)