gibbo1715 Posted December 2, 2009 Share Posted December 2, 2009 All Im still trying to learn arrays and have the following A user table that contains a group id (varchar(200) that contains the following 1,0,1,1,0 I want to display the groups my user has access to and am trying the following but it only displays group 1 when i know there is also accees to groups 3 and 4 Can anyone see what i ve got wrong please, the user is logged on and I can get the user id <?php Include("models/config.php"); If(isUserLoggedIn()) { echo "Logged In"; echo "<br>"; $group = $loggedInUser->groupID(); $usergroups = explode(",",$group['Group_ID']); $groups = array('usergroup 1','usergroup 2','usergroup 3','usergroup 4','usergroup 5'); //if statement for($x = 0; $x < count($usergroups); $x++) { if($usergroups][$x]) { // display the menu item print $groups[$x]."<br />"; } } } else { echo "Log In"; } ?> thanks gibbo my groupid() function is as follows //Fetch all user group information public function groupID() { global $db,$db_table_prefix; $sql = "SELECT ".$db_table_prefix."Users.Group_ID, ".$db_table_prefix."Groups.* FROM ".$db_table_prefix."Users INNER JOIN ".$db_table_prefix."Groups ON ".$db_table_prefix."Users.Group_ID = ".$db_table_prefix."Groups.Group_ID WHERE User_ID = '".(int)$this->user_id."'"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); return($row); } Link to comment https://forums.phpfreaks.com/topic/183722-array-question/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.