Perad Posted December 30, 2006 Share Posted December 30, 2006 Right, i have an admin query.[code]global $dbc, $user_id, $uncaccess; $adminaccess = 0; $query = "SELECT user_id=$user_id FROM unc_user_group WHERE group_id=2;"; $result = mysql_query($query)or die(mysql_error());; $row = (mysql_fetch_assoc ($result)); if (($row['user_id='.$user_id])==1) { $uncaccess = 1; echo '<a href="folder/admin.php">Admin Control Panel</a>'; } else { $uncaccess = 0;}[/code]This is simply used to display a link to the admin panel.The idea simply is to simply check against the forums user group to see if you fall into the admin category. The problem with this is that if you are in more than one group the test often fails.For example.My top admin account gets the following back from the query10My secondary admin account gets out01The query interprets the second user as not having admin privileges$user_id simply gets the users id. This is then checked against the following table.group_id user_id user_pending1 -1 0Could someone help me fix this query so that it always finds the number 1 no matter what order the numbers come out in. Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 30, 2006 Share Posted December 30, 2006 Unless I'm mistaken, that query will return a record for every row in the table. I'm assuming you just have two accounts in there at the moment. A better approach would be to query records where the user id is the one you are interested in where it exists in group 2. If any record is returned the user is an admin.[code]<?phpglobal $dbc, $user_id, $uncaccess;$adminaccess = 0;$query = "SELECT * FROM unc_user_group WHERE group_id=2 AND user_id=".$user_id;$result = mysql_query($query)or die(mysql_error());;if (mysql_num_rows($result)>0) { $uncaccess = 1; echo '<a href="folder/admin.php">Admin Control Panel</a>';} else { $uncaccess = 0;}?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.