imafish Posted July 23, 2006 Share Posted July 23, 2006 HiI've got two tables, one is the name of the group the other is the memberships the user is in.I want a all the groups to come up, but the groups the user is in to be ticked.I can make the list of groups the user is in come up, but not the rest of the groups the user [i]isn't[/i] in.Thanks Quote Link to comment https://forums.phpfreaks.com/topic/15374-stuck-list-checkboxes-only-some-ticked/ Share on other sites More sharing options...
Branden Wagner Posted July 23, 2006 Share Posted July 23, 2006 im not sure... can you give me an example of a user, the groups hes in, and the groups hes NOT in.and ill give it a shot. Quote Link to comment https://forums.phpfreaks.com/topic/15374-stuck-list-checkboxes-only-some-ticked/#findComment-62303 Share on other sites More sharing options...
kenrbnsn Posted July 23, 2006 Share Posted July 23, 2006 Can you post any code you've already written and the script for the form? Without these we would be grasping at straws for solutions.Ken Quote Link to comment https://forums.phpfreaks.com/topic/15374-stuck-list-checkboxes-only-some-ticked/#findComment-62304 Share on other sites More sharing options...
imafish Posted July 23, 2006 Author Share Posted July 23, 2006 Ok.User 60 is in groups: supermarket, bottleshop, petrolstation, firehouseIS NOT in the rest;garage, garden, busstop, airport, boat, policehousethey should all come up in the list, but only [b]supermarket, bottleshop, petrolstation, firehouse[/b] should be ticked. Quote Link to comment https://forums.phpfreaks.com/topic/15374-stuck-list-checkboxes-only-some-ticked/#findComment-62307 Share on other sites More sharing options...
imafish Posted July 23, 2006 Author Share Posted July 23, 2006 Here is what I have got, that selects the groups (from the group table) that the user is in. All I need to add is the OTHER group names, that are not selected. [code]//Query the table to see if the user is part of any groups $query_groupsmember = "SELECT u.id, um.id, u.name, u.description, um.userid, um.groupid FROM usersgroup u, usersmembership um WHERE userid=$userid AND um.groupid = u.id;"; $result_groupsmember = mysql_query($query_groupsmember) or die ('Query failed: ' . mysql_error()); while($row = mysql_fetch_array($result_groupsmember, MYSQL_ASSOC)){ //Displays and marks the existing groups echo "<tr><td>"; $groupname = $row['name']; $groupdesc = $row['description']; $groupid = $row['id']; $group_group = $row['groupid']; echo "<input type=\"checkbox\" checked=\"yes\" id=\"$groupid\" value=\"$groupname\" title=\"$groupdesc\">$groupname<br>"; echo "<td></tr>"; }[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15374-stuck-list-checkboxes-only-some-ticked/#findComment-62309 Share on other sites More sharing options...
Branden Wagner Posted July 23, 2006 Share Posted July 23, 2006 its getting late and im having a hard time thinking here...what table shows the list of groups the user is in and how is that formattedthe way i would have itTable: groupsuserid | group1 id | group2 id | ... |---------------------------------- 101 | 1 | 0 | 0 |basically shows the userid and if the user is in the group marks it with a 1, if its a 0 user is not in the group.then you just make a for loop with an if else statement. Quote Link to comment https://forums.phpfreaks.com/topic/15374-stuck-list-checkboxes-only-some-ticked/#findComment-62312 Share on other sites More sharing options...
imafish Posted July 23, 2006 Author Share Posted July 23, 2006 SorryThe tables are[b]groupsuser[/b]groupid | userid 9 | 60 5 | 60 3 | 60[b]groups[/b]groupid | name 1 | firestation 2 | police 3 | supermarketSo groupuser links to groups, so a user can be in many groups. Quote Link to comment https://forums.phpfreaks.com/topic/15374-stuck-list-checkboxes-only-some-ticked/#findComment-62314 Share on other sites More sharing options...
Branden Wagner Posted July 23, 2006 Share Posted July 23, 2006 well im brain dead for the night, thats a pretty difficult question.. ill look back at it tomorrow when im refreshed and see if i can figure it out for you.my preference would be to rewrite the groups table like i mentioned previously. Quote Link to comment https://forums.phpfreaks.com/topic/15374-stuck-list-checkboxes-only-some-ticked/#findComment-62318 Share on other sites More sharing options...
kenrbnsn Posted July 23, 2006 Share Posted July 23, 2006 What you probably want to do is create an array that holds all of the possible groups. Then in the while loop, collect all the groups the user is a member of in another array. After that array is created, a use a foreach loop on the first array, checking to see if each group is in the user's array, if it is, check it.Ken Quote Link to comment https://forums.phpfreaks.com/topic/15374-stuck-list-checkboxes-only-some-ticked/#findComment-62321 Share on other sites More sharing options...
imafish Posted July 23, 2006 Author Share Posted July 23, 2006 Thanks for that;I've just started it!Except I get only the last member of the array.Ive created an array by going$a = array($groupnamelist);that correct? Quote Link to comment https://forums.phpfreaks.com/topic/15374-stuck-list-checkboxes-only-some-ticked/#findComment-62322 Share on other sites More sharing options...
kenrbnsn Posted July 23, 2006 Share Posted July 23, 2006 Please post the code you're working with, posting one line out of context is not useful.Ken Quote Link to comment https://forums.phpfreaks.com/topic/15374-stuck-list-checkboxes-only-some-ticked/#findComment-62323 Share on other sites More sharing options...
imafish Posted July 23, 2006 Author Share Posted July 23, 2006 [code]while($row = mysql_fetch_array($result_groupsmember, MYSQL_ASSOC)){ //Get all groups user is part of and store in an array //echo $row['name']; $a = array($row['name']); }[/code]Basically I want it so that each item from $row['name'] goes into the array. Quote Link to comment https://forums.phpfreaks.com/topic/15374-stuck-list-checkboxes-only-some-ticked/#findComment-62324 Share on other sites More sharing options...
kenrbnsn Posted July 23, 2006 Share Posted July 23, 2006 Try:[code]<?php$a = array()while($row = mysql_fetch_array($result_groupsmember, MYSQL_ASSOC)){ //Get all groups user is part of and store in an array //echo $row['name']; $a[] = $row['name']; }?>[/code]Initialize the array first, then add each name into it.Ken Quote Link to comment https://forums.phpfreaks.com/topic/15374-stuck-list-checkboxes-only-some-ticked/#findComment-62327 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.