我有一个基于控制台的网站,我无法弄清楚如何使用$consoleORDER
值对数据进行排序。
基本上我正在努力使每个类别按ordernum
排序。
编辑:好的抱歉因缺乏细节而忘记没有人看到实际的代码执行我大声笑。
$dispConsoleFeatures = "";
$consoleAdmin = "";
$consoleStaff = "";
$consoleAccount = "";
$consoleMember = "";
$consoleNews = "";
$consoleRecruitment = "";
$consoleSecurity = "";
$consoleDivision = "";
$consoleTourny = "";
$consoleTraining = "";
$consoleAwards = "";
$consoleInfo = "";
$consoleUnknown = "";
$memConsole = getMemberInfo("console_options", $membername);
$ConsoleIDs = explode("[sep]", $memConsole);
foreach($ConsoleIDs as $console) {
$consoleORDER = getConsoleInfo2("ordernum", $console);
$consoleLINK = getConsoleInfo2("id", $console);
$consoleNAME = getConsoleInfo2("displayname", $console);
$consoleHIDE = getConsoleInfo2("hide", $console);
$consoleCATEGORY = getConsoleInfo2("category", $console);
$consoleAdmin_I = "<tr><td align='left'> <img src='images/console/admin.png'><br></td></tr>";
$consoleStaff_I = "<tr><td align='left'> <img src='images/console/staff.png'><br></td></tr>";
$consoleAccount_I = "<tr><td align='left'> <img src='images/console/account.png'><br></td></tr>";
$consoleMember_I = "<tr><td align='left'> <img src='images/console/member.png'><br></td></tr>";
$consoleNews_I = "<tr><td align='left'> <img src='images/console/news.png'><br></td></tr>";
$consoleRecruitment_I = "<tr><td align='left'> <img src='images/console/recruitment.png'><br></td></tr>";
$consoleSecurity_I = "<tr><td align='left'> <img src='images/console/security.png'><br></td></tr>";
$consoleDivision_I = "<tr><td align='left'> <img src='images/console/division.png'><br></td></tr>";
$consoleTourny_I = "<tr><td align='left'> <img src='images/console/tourny.png'><br></td></tr>";
$consoleTraining_I = "<tr><td align='left'> <img src='images/console/training.png'><br></td></tr>";
$consoleAwards_I = "<tr><td align='left'> <img src='images/console/awards.png'><br></td></tr>";
$consoleInfo_I = "<tr><td align='left'> <img src='images/console/info.png'><br></td></tr>";
$consoleUnknown_I = "<tr><td align='left'> <img src='images/console/unknown.png'><br></td></tr>";
if($console != "" AND $consoleHIDE == "0") {
if($consoleCATEGORY == "1") {
$consoleAdmin .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat1 = "$consoleAdmin_I<tr><td class='main' align='left'>$consoleAdmin</td></tr>";
} elseif($consoleCATEGORY == "2") {
$consoleMember .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat2 = "$consoleMember_I<tr><td class='main' align='left'>$consoleMember</td></tr>";
} elseif($consoleCATEGORY == "3") {
$consoleAccount .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat3 = "$consoleAccount_I<tr><td class='main' align='left'>$consoleAccount</td></tr>";
} elseif($consoleCATEGORY == "4") {
$consoleStaff .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat4 = "$consoleStaff_I<tr><td class='main' align='left'>$consoleStaff</td></tr>";
} elseif($consoleNews == "5") {
$consoleNews .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat5 = "$consoleNews_I<tr><td class='main' align='left'>$consoleNews</td></tr>";
} elseif($consoleCATEGORY == "7") {
$consoleDivision .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat7 = "$consoleDivision_I<tr><td class='main' align='left'>$consoleDivision</td></tr>";
} elseif($consoleCATEGORY == "8") {
$consoleTourny .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat8 = "$consoleTourny_I<tr><td class='main' align='left'>$consoleTourny</td></tr>";
} elseif($consoleCATEGORY == "9") {
$consoleNews .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat9 = "$consoleNews_I<tr><td class='main' align='left'>$consoleNews</td></tr>";
} elseif($consoleCATEGORY == "10") {
$consoleAwards .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat10 = "$consoleAwards_I<tr><td class='main' align='left'>$consoleAwards</td></tr>";
} elseif($consoleCATEGORY == "11") {
$consoleSecurity .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat11 = "$consoleSecurity_I<tr><td class='main' align='left'>$consoleSecurity</td></tr>";
} elseif($consoleCATEGORY == "12") {
$consoleRecruitment .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat12 = "$consoleRecruitment_I<tr><td class='main' align='left'>$consoleRecruitment</td></tr>";
} elseif($consoleCATEGORY == "14") {
$consoleTraining .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat14 = "$consoleTraining_I<tr><td class='main' align='left'>$consoleTraining</td></tr>";
} elseif($consoleCATEGORY == "15") {
$consoleUnknown .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat15 = "$consoleUnknown_I<tr><td class='main' align='left'>$consoleUnknown</td></tr>";
} elseif($consoleCATEGORY == "16") {
$consoleInfo .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat16 = "$consoleInfo_I<tr><td class='main' align='left'>$consoleInfo</td></tr>";
}
$dispConsoleFeatures = "<tr><td class='main' align='center'> <img src='images/console/console.png'><br></td></tr>$dispCat1$dispCat4$dispCat2$dispCat11$dispCat12$dispCat10$dispCat14$dispCat8$dispCat9$dispCat5$dispCat7$dispCat3<br>$dispCat16<br>$dispCat15";
}
}
最终结果是:
显然我不允许发布图片了。有点烦人。所以我在这里上传了tyhe图片。
http://www.swfclan.com/snippet1.jpg
正如你在“锦标赛”中所看到的那样,这是错误的,因为在我开始重新排列之前,我从没想过它是如何订购的。问题是订单被假定为(从上到下)进入锦标赛,创建锦标赛,添加锦标赛员工,删除锦标赛员工,锦标赛选项。
Varaible $ memConsole是从成员数据中提取的,每个都是一个数字,它使用该数字来检索其余信息。
答案 0 :(得分:1)
正如@MikeBrant在评论中提到的那样,用提供的代码很难掌握结构。但我确实试图这样做。我将所有内容放入ordernum
作为key
的数组中,然后使用ksort
进行排序。你可能不得不玩一下。
此外,我更改了您的if-elseif
至swicth
个人资料,个人偏好更容易理解:
注意:我注释了您的功能并更改了foreach
以进行测试。
$orderNum = array(1, 99, 15);
$i = 0;
foreach($orderNum as $oNum) {
//$consoleORDER = getConsoleInfo2("ordernum", $console);
$consoleORDER = $oNum;
//$consoleArray['orderNum'][$consoleORDER]['LINK'] = getConsoleInfo2("id", $console);
$consoleArray['orderNum'][$consoleORDER]['LINK'] = "Link";
//$consoleArray['orderNum'][$consoleORDER]['NAME'] = getConsoleInfo2("displayname", $console);
$consoleArray['orderNum'][$consoleORDER]['NAME'] = "name";
//$consoleArray['orderNum'][$consoleORDER]['HIDE'] = getConsoleInfo2("hide", $console);
$consoleArray['orderNum'][$consoleORDER]['HIDE'] = "hide";
//$consoleArray['orderNum'][$consoleORDER]['CATEGORY'] = getConsoleInfo2("category", $console);
$consoleArray['orderNum'][$consoleORDER]['CATEGORY'] = "category";
$consoleArray['orderNum'][$consoleORDER]['Admin_I'] = "<tr><td align='left'> <img src='images/console/admin.png'><br></td></tr>";
$consoleArray['orderNum'][$consoleORDER]['Staff_I'] = "<tr><td align='left'> <img src='images/console/staff.png'><br></td></tr>";
$consoleArray['orderNum'][$consoleORDER]['Account_I'] = "<tr><td align='left'> <img src='images/console/account.png'><br></td></tr>";
$consoleArray['orderNum'][$consoleORDER]['Member_I'] = "<tr><td align='left'> <img src='images/console/member.png'><br></td></tr>";
$consoleArray['orderNum'][$consoleORDER]['News_I'] = "<tr><td align='left'> <img src='images/console/news.png'><br></td></tr>";
$consoleArray['orderNum'][$consoleORDER]['Recruitment_I'] = "<tr><td align='left'> <img src='images/console/recruitment.png'><br></td></tr>";
$consoleArray['orderNum'][$consoleORDER]['Security_I'] = "<tr><td align='left'> <img src='images/console/security.png'><br></td></tr>";
$consoleArray['orderNum'][$consoleORDER]['Division_I'] = "<tr><td align='left'> <img src='images/console/division.png'><br></td></tr>";
$consoleArray['orderNum'][$consoleORDER]['Tourny_I'] = "<tr><td align='left'> <img src='images/console/tourny.png'><br></td></tr>";
$consoleArray['orderNum'][$consoleORDER]['Training_I'] = "<tr><td align='left'> <img src='images/console/training.png'><br></td></tr>";
$consoleArray['orderNum'][$consoleORDER]['Awards_I'] = "<tr><td align='left'> <img src='images/console/awards.png'><br></td></tr>";
$consoleArray['orderNum'][$consoleORDER]['Info_I'] = "<tr><td align='left'> <img src='images/console/info.png'><br></td></tr>";
$consoleArray['orderNum'][$consoleORDER]['Unknown_I']= "<tr><td align='left'> <img src='images/console/unknown.png'><br></td></tr>";
####################################################################
## OTHER THAN THE CASE-SWITCH I DID NOT MODIFY THE FOLLOWING CODE ##
####################################################################
if($console != "" && $consoleHIDE == "0") {
switch ($consoleCATEGORY) {
case "1":
$consoleAdmin .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat1 = "$consoleAdmin_I<tr><td class='main' align='left'>$consoleAdmin</td></tr>";
break;
case "2":
$consoleMember .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat2 = "$consoleMember_I<tr><td class='main' align='left'>$consoleMember</td></tr>";
break;
case "3":
$consoleAccount .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat3 = "$consoleAccount_I<tr><td class='main' align='left'>$consoleAccount</td></tr>";
break;
case "4":
$consoleStaff .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat4 = "$consoleStaff_I<tr><td class='main' align='left'>$consoleStaff</td></tr>";
break;
case "5":
$consoleNews .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat5 = "$consoleNews_I<tr><td class='main' align='left'>$consoleNews</td></tr>";
break;
case "6":
// Missing 6
break;
case "7":
$consoleDivision .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat7 = "$consoleDivision_I<tr><td class='main' align='left'>$consoleDivision</td></tr>";
break;
case "8":
$consoleTourny .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat8 = "$consoleTourny_I<tr><td class='main' align='left'>$consoleTourny</td></tr>";
break;
case "9":
$consoleNews .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat9 = "$consoleNews_I<tr><td class='main' align='left'>$consoleNews</td></tr>";
break;
case "10":
$consoleAwards .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat10 = "$consoleAwards_I<tr><td class='main' align='left'>$consoleAwards</td></tr>";
break;
case "11":
$consoleSecurity .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat11 = "$consoleSecurity_I<tr><td class='main' align='left'>$consoleSecurity</td></tr>";
break;
case "12":
$consoleRecruitment .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat12 = "$consoleRecruitment_I<tr><td class='main' align='left'>$consoleRecruitment</td></tr>";
break;
case "13":
// Missing 13
break;
case "14":
$consoleTraining .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat14 = "$consoleTraining_I<tr><td class='main' align='left'>$consoleTraining</td></tr>";
break;
case "15":
$consoleUnknown .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat15 = "$consoleUnknown_I<tr><td class='main' align='left'>$consoleUnknown</td></tr>";
break;
case "16":
$consoleInfo .= " <a href='console.php?pid=$consoleLINK'>$consoleNAME</a><br>";
$dispCat16 = "$consoleInfo_I<tr><td class='main' align='left'>$consoleInfo</td></tr>";
break;
}
$dispConsoleFeatures = "<tr><td class='main' align='center'> <img src='images/console/console.png'><br></td></tr>$dispCat1$dispCat4$dispCat2$dispCat11$dispCat12$dispCat10$dispCat14$dispCat8$dispCat9$dispCat5$dispCat7$dispCat3<br>$dispCat16<br>$dispCat15";
}
$i++;
}
ksort($consoleArray['orderNum']);
echo '<pre>', print_r($consoleArray, true), '</pre>';
<强>输出继电器:强>
Array
(
[orderNum] => Array
(
[1] => Array
(
[LINK] => Link
[NAME] => name
[HIDE] => hide
[CATEGORY] => category
[Admin_I] => <tr><td align='left'> <img src='images/console/admin.png'><br></td></tr>
[Staff_I] => <tr><td align='left'> <img src='images/console/staff.png'><br></td></tr>
[Account_I] => <tr><td align='left'> <img src='images/console/account.png'><br></td></tr>
[Member_I] => <tr><td align='left'> <img src='images/console/member.png'><br></td></tr>
[News_I] => <tr><td align='left'> <img src='images/console/news.png'><br></td></tr>
[Recruitment_I] => <tr><td align='left'> <img src='images/console/recruitment.png'><br></td></tr>
[Security_I] => <tr><td align='left'> <img src='images/console/security.png'><br></td></tr>
[Division_I] => <tr><td align='left'> <img src='images/console/division.png'><br></td></tr>
[Tourny_I] => <tr><td align='left'> <img src='images/console/tourny.png'><br></td></tr>
[Training_I] => <tr><td align='left'> <img src='images/console/training.png'><br></td></tr>
[Awards_I] => <tr><td align='left'> <img src='images/console/awards.png'><br></td></tr>
[Info_I] => <tr><td align='left'> <img src='images/console/info.png'><br></td></tr>
[Unknown_I] => <tr><td align='left'> <img src='images/console/unknown.png'><br></td></tr>
)
[15] => Array
(
[LINK] => Link
[NAME] => name
[HIDE] => hide
[CATEGORY] => category
[Admin_I] => <tr><td align='left'> <img src='images/console/admin.png'><br></td></tr>
[Staff_I] => <tr><td align='left'> <img src='images/console/staff.png'><br></td></tr>
[Account_I] => <tr><td align='left'> <img src='images/console/account.png'><br></td></tr>
[Member_I] => <tr><td align='left'> <img src='images/console/member.png'><br></td></tr>
[News_I] => <tr><td align='left'> <img src='images/console/news.png'><br></td></tr>
[Recruitment_I] => <tr><td align='left'> <img src='images/console/recruitment.png'><br></td></tr>
[Security_I] => <tr><td align='left'> <img src='images/console/security.png'><br></td></tr>
[Division_I] => <tr><td align='left'> <img src='images/console/division.png'><br></td></tr>
[Tourny_I] => <tr><td align='left'> <img src='images/console/tourny.png'><br></td></tr>
[Training_I] => <tr><td align='left'> <img src='images/console/training.png'><br></td></tr>
[Awards_I] => <tr><td align='left'> <img src='images/console/awards.png'><br></td></tr>
[Info_I] => <tr><td align='left'> <img src='images/console/info.png'><br></td></tr>
[Unknown_I] => <tr><td align='left'> <img src='images/console/unknown.png'><br></td></tr>
)
[99] => Array
(
[LINK] => Link
[NAME] => name
[HIDE] => hide
[CATEGORY] => category
[Admin_I] => <tr><td align='left'> <img src='images/console/admin.png'><br></td></tr>
[Staff_I] => <tr><td align='left'> <img src='images/console/staff.png'><br></td></tr>
[Account_I] => <tr><td align='left'> <img src='images/console/account.png'><br></td></tr>
[Member_I] => <tr><td align='left'> <img src='images/console/member.png'><br></td></tr>
[News_I] => <tr><td align='left'> <img src='images/console/news.png'><br></td></tr>
[Recruitment_I] => <tr><td align='left'> <img src='images/console/recruitment.png'><br></td></tr>
[Security_I] => <tr><td align='left'> <img src='images/console/security.png'><br></td></tr>
[Division_I] => <tr><td align='left'> <img src='images/console/division.png'><br></td></tr>
[Tourny_I] => <tr><td align='left'> <img src='images/console/tourny.png'><br></td></tr>
[Training_I] => <tr><td align='left'> <img src='images/console/training.png'><br></td></tr>
[Awards_I] => <tr><td align='left'> <img src='images/console/awards.png'><br></td></tr>
[Info_I] => <tr><td align='left'> <img src='images/console/info.png'><br></td></tr>
[Unknown_I] => <tr><td align='left'> <img src='images/console/unknown.png'><br></td></tr>
)
)
)
这接近你想要的吗?