CMellor Posted March 9, 2007 Share Posted March 9, 2007 'lo all, I come seeking help! lol I've been racking my brain and tried many codes to get this to work and can't seem to get close to how I want it. I am using the tables from Invision Power Board and made a drop down box with the list of user groups, but only limited it to show three of the groups instead of them all. The users are in different groups. I have a list of all my users and next to it is that drop down box listing the groups, now what I want is to have the correct group selected for that user, but I can't seem to manage that, so any help would be appreciated. Here's the code: <select name="brand"> '); // query $group_query = mysql_query("SELECT * FROM ibf_groups WHERE g_id = 3 OR g_id = 6 OR g_id = 7"); // fetch data while($groups = mysql_fetch_array($group_query)) { $_POST['mgroup'] == $groups['g_id'] ? $selected = 'selected' : $selected = ''; echo(' <option value="'.$groups['g_id'].'" '.$selected.'>'.$groups['g_title'].'</option> '); } echo(' </select> This is a snippet of the code. I thought adding the group ID to a hidden field could work, that's why theirs a $_POST var in that code. So hope I made sense and look forward to hearing from you. Chris. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 9, 2007 Share Posted March 9, 2007 Try <?php echo '<select name="brand">'; // query $group_query = mysql_query("SELECT * FROM ibf_groups WHERE g_id IN (3,6,7) "); // fetch data while($groups = mysql_fetch_array($group_query)) { $selected = $_POST['mgroup'] == $groups['g_id'] ? 'selected' : ''; echo(' <option value="'.$groups['g_id'].'" '.$selected.'>'.$groups['g_title'].'</option> '); } echo(' </select>'; ?> Quote Link to comment Share on other sites More sharing options...
CMellor Posted March 9, 2007 Author Share Posted March 9, 2007 Hey, thanks for the reply, Sadly that didn't work the current selected option is the first one for each member. Any more help is appreciated. Chris. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 9, 2007 Share Posted March 9, 2007 Can you post your table structures for groups and users Quote Link to comment Share on other sites More sharing options...
CMellor Posted March 9, 2007 Author Share Posted March 9, 2007 Hmmm... am assuming you mean these, their pretty long: -- -- Table structure for table `ibf_groups` -- CREATE TABLE `ibf_groups` ( `g_id` int(3) unsigned NOT NULL auto_increment, `g_view_board` tinyint(1) default NULL, `g_mem_info` tinyint(1) default NULL, `g_other_topics` tinyint(1) default NULL, `g_use_search` tinyint(1) default NULL, `g_email_friend` tinyint(1) default NULL, `g_invite_friend` tinyint(1) default NULL, `g_edit_profile` tinyint(1) default NULL, `g_post_new_topics` tinyint(1) default NULL, `g_reply_own_topics` tinyint(1) default NULL, `g_reply_other_topics` tinyint(1) default NULL, `g_edit_posts` tinyint(1) default NULL, `g_delete_own_posts` tinyint(1) default NULL, `g_open_close_posts` tinyint(1) default NULL, `g_delete_own_topics` tinyint(1) default NULL, `g_post_polls` tinyint(1) default NULL, `g_vote_polls` tinyint(1) default NULL, `g_use_pm` tinyint(1) default '0', `g_is_supmod` tinyint(1) default NULL, `g_access_cp` tinyint(1) default NULL, `g_title` varchar(32) NOT NULL default '', `g_can_remove` tinyint(1) default NULL, `g_append_edit` tinyint(1) default NULL, `g_access_offline` tinyint(1) default NULL, `g_avoid_q` tinyint(1) default NULL, `g_avoid_flood` tinyint(1) default NULL, `g_icon` text NOT NULL, `g_attach_max` bigint(20) default NULL, `g_avatar_upload` tinyint(1) default '0', `prefix` varchar(250) default NULL, `suffix` varchar(250) default NULL, `g_max_messages` int(5) default '50', `g_max_mass_pm` int(5) default '0', `g_search_flood` mediumint(6) default '20', `g_edit_cutoff` int(10) default '0', `g_promotion` varchar(10) default '-1&-1', `g_hide_from_list` tinyint(1) default '0', `g_post_closed` tinyint(1) default '0', `g_perm_id` varchar(255) NOT NULL default '', `g_photo_max_vars` varchar(200) default '100:150:150', `g_dohtml` tinyint(1) NOT NULL default '0', `g_edit_topic` tinyint(1) NOT NULL default '0', `g_email_limit` varchar(15) NOT NULL default '10:15', `g_bypass_badwords` tinyint(1) NOT NULL default '0', `g_can_msg_attach` tinyint(1) NOT NULL default '0', `g_attach_per_post` int(10) NOT NULL default '0', `g_topic_rate_setting` smallint(2) NOT NULL default '0', `g_dname_changes` int(3) NOT NULL default '0', `g_dname_date` int(5) NOT NULL default '0', `g_blog_attach_max` int(10) NOT NULL default '-1', `g_blog_attach_per_entry` int(10) NOT NULL default '0', `g_blog_do_html` tinyint(1) NOT NULL default '0', `g_blog_do_commenthtml` tinyint(1) NOT NULL default '0', `g_blog_allowpoll` tinyint(1) NOT NULL default '0', `g_blog_allowprivate` tinyint(1) NOT NULL default '0', `g_blog_allowprivclub` tinyint(1) NOT NULL default '0', `g_blog_alloweditors` tinyint(1) NOT NULL default '0', `g_blog_allowskinchoose` tinyint(1) NOT NULL default '0', `g_blog_preventpublish` tinyint(1) NOT NULL default '0', PRIMARY KEY (`g_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ; -- -- Table structure for table `ibf_members` -- CREATE TABLE `ibf_members` ( `id` mediumint( NOT NULL default '0', `name` varchar(255) NOT NULL default '', `mgroup` smallint(3) NOT NULL default '0', `email` varchar(150) NOT NULL default '', `joined` int(10) NOT NULL default '0', `ip_address` varchar(16) NOT NULL default '', `posts` mediumint(7) default '0', `title` varchar(64) default NULL, `allow_admin_mails` tinyint(1) default NULL, `time_offset` varchar(10) default NULL, `hide_email` varchar( default NULL, `email_pm` tinyint(1) default '1', `email_full` tinyint(1) default NULL, `skin` smallint(5) default NULL, `warn_level` int(10) default NULL, `warn_lastwarn` int(10) NOT NULL default '0', `language` varchar(32) default NULL, `last_post` int(10) default NULL, `restrict_post` varchar(100) NOT NULL default '0', `view_sigs` tinyint(1) default '1', `view_img` tinyint(1) default '1', `view_avs` tinyint(1) default '1', `view_pop` tinyint(1) default '1', `bday_day` int(2) default NULL, `bday_month` int(2) default NULL, `bday_year` int(4) default NULL, `new_msg` tinyint(2) default '0', `msg_total` smallint(5) default '0', `show_popup` tinyint(1) default '0', `misc` varchar(128) default NULL, `last_visit` int(10) default '0', `last_activity` int(10) default '0', `dst_in_use` tinyint(1) default '0', `view_prefs` varchar(64) default '-1&-1', `coppa_user` tinyint(1) default '0', `mod_posts` varchar(100) NOT NULL default '0', `auto_track` varchar(50) default '0', `temp_ban` varchar(100) default '0', `sub_end` int(10) NOT NULL default '0', `login_anonymous` char(3) NOT NULL default '0&0', `ignored_users` text NOT NULL, `mgroup_others` varchar(255) NOT NULL default '', `org_perm_id` varchar(255) NOT NULL default '', `member_login_key` varchar(32) NOT NULL default '', `member_login_key_expire` int(10) NOT NULL default '0', `subs_pkg_chosen` smallint(3) NOT NULL default '0', `has_blog` tinyint(1) NOT NULL default '0', `has_gallery` tinyint(1) NOT NULL default '0', `members_markers` text NOT NULL, `members_editor_choice` char(3) NOT NULL default 'std', `members_auto_dst` tinyint(1) NOT NULL default '1', `members_display_name` varchar(255) NOT NULL default '', `members_created_remote` tinyint(1) NOT NULL default '0', `members_cache` mediumtext, `members_disable_pm` int(1) NOT NULL default '0', `members_l_display_name` varchar(255) NOT NULL default '0', `members_l_username` varchar(255) NOT NULL default '0', `failed_logins` text, `failed_login_count` smallint(3) NOT NULL default '0', `members_profile_views` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`id`), KEY `members_l_display_name` (`members_l_display_name`), KEY `members_l_username` (`members_l_username`), KEY `mgroup` (`mgroup`), KEY `bday_day` (`bday_day`), KEY `bday_month` (`bday_month`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; Quote Link to comment Share on other sites More sharing options...
CMellor Posted March 9, 2007 Author Share Posted March 9, 2007 Note, tried editing my last post but it wouldn't let me. Nevermind, figured it out *finally* If interested, here's the code: <select name="brand"> // query $group_query = mysql_query("SELECT * FROM ibf_groups, ibf_members WHERE ibf_groups.g_id = ibf_members.id AND g_id IN(3, 4, 6, 7)"); // fetch data while($groups = mysql_fetch_array($group_query)) { $selected = $row['mgroup'] == $groups['g_id'] ? 'selected' : ''; echo(' <option value="'.$groups['g_id'].'" '.$selected.'>'.$groups['g_title'].'</option> '); } </select> I just used a different query. Thanks for the help though Barand! Quote Link to comment Share on other sites More sharing options...
Barand Posted March 9, 2007 Share Posted March 9, 2007 My first comment is with tables like that, or any table for that matter, don't use "SELECT * " when all you need is the "id" and the "title". It just wastes resources. Try something like this <?php function selectGroup ($current) { $sql = "SELECT g_id, g_title FROM `ibf_groups` WHERE g_id IN (3,6,7) ORDER BY g_title"; $res = mysql_query($sql) or die (mysql_error().'<p>$sql</p>'); $str = "<select name='group'>\n"; $str .= "<option value=''>- select group -</option>\n"; while (list($id, $title) = mysql_fetch_row($res)) { $select = $id==$current ? 'selected' : ''; $str .= "<option value='$id'> $title</option\n"; } $str .= "</select\n"; return $str; } // list members names with group dropdowns $sql = "SELECT name, mgroup FROM ibf_members ORDER BY name"; $res = mysql_query($sql) or die (mysql_error().'<p>$sql</p>'); while (list($id, $name, $gp) = mysql_fetch_row($res)) { echo selectGroup($gp) . " $name <br/>"; } ?> 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.