基本上我試圖限制什麼登錄用戶可以看到取決於他們的排名是什麼。內容是幾行,都有不同的等級要求。如果用戶沒有所需的排名,他將無法查看該行。 但是,我的問題在於,如果一行的排名要求高於其下的任何行,並且用戶沒有該排名,那麼下面的所有行也都將不可見。限制內容的用戶排名
public function Categories() {
global $Template, $CatArray;
$CatArray = array();
$PermissionTable = array();
$QueryCat = $this->mysqli->query("SELECT * FROM categories ORDER BY id ASC");
while($FetchCat = $QueryCat->fetch_array()) {
$PermissionTable["category"] = array("id" => $FetchCat["id"]); // store category ID as an id sub-array
$data = explode(",", $FetchCat["ranks"]); // the ranks row in the database contains all ranks that can see this category, so here we split them up.
foreach($data as $number) {
$PermissionTable["category"] += array(
"rank" => $data // apply rank requirements in a sub-array again
);
}
if(in_array($Template["user"]["user_group"], $PermissionTable["category"]["rank"])) { // here, if the users rank is in the rank sub-array, they will be able to see it
$CatArray[] = $FetchCat;
} else { // otherwise display nothing
$CatArray[] = null;
}
}
$Template["CatArray"] = $CatArray;
return $CatArray;
}
你不能只是將用戶當前的等級添加到查詢中,如'WHERE rowRank <= userRank' – RiggsFolly
不,因爲等級表看起來像1,2,3,4,5等,所以我不能使用<= opreator(它不是基於最小值需要排名,但是它在表格中寫下了什麼排名) –
請向我們展示您的數據庫結構,以及您需要做什麼的真實示例。例如,用戶X有1,4,8個等級,他需要看到類別a,b和c。 –