Xtremer360 Posted March 13, 2012 Share Posted March 13, 2012 I'm trying to have it shows the data from my array as each option will have a value of the user's id and the text for the option will be their name. As of right now it only shows the last person. <?php echo form_label('Recipient', 'recipient'); ?> <?php $data = array( 'name' => 'to', 'class' => 'required' ); <?php echo form_label('Recipient', 'recipient'); ?> <?php $data = array( 'name' => 'to', 'class' => 'required' ); $options = array(); foreach($users AS $user) { $options = array ( $user->user_id => $user->first_name.' '.$user->last_name ); } ?> <?php echo form_dropdown($data, $options); ?> Quote Link to comment https://forums.phpfreaks.com/topic/258852-dropdown/ Share on other sites More sharing options...
smerny Posted March 13, 2012 Share Posted March 13, 2012 because you keep replacing the options array rather than adding to it. i'm not sure what form_dropdown() consists of, but try changing: $options = array ( to $options[] = array ( Quote Link to comment https://forums.phpfreaks.com/topic/258852-dropdown/#findComment-1326993 Share on other sites More sharing options...
Xtremer360 Posted March 13, 2012 Author Share Posted March 13, 2012 Didn't change anything unfortunately. Quote Link to comment https://forums.phpfreaks.com/topic/258852-dropdown/#findComment-1326995 Share on other sites More sharing options...
smerny Posted March 13, 2012 Share Posted March 13, 2012 actually, just looked up form_dropdown (codeignitor) try this: foreach($users AS $user) { $options[$user->user_id] = $user->first_name.' '.$user->last_name; } Quote Link to comment https://forums.phpfreaks.com/topic/258852-dropdown/#findComment-1326996 Share on other sites More sharing options...
Xtremer360 Posted March 13, 2012 Author Share Posted March 13, 2012 Only problem with that is that the value of the option should be the user_id and the text of the option should be the users name. Quote Link to comment https://forums.phpfreaks.com/topic/258852-dropdown/#findComment-1326997 Share on other sites More sharing options...
Mahngiel Posted March 13, 2012 Share Posted March 13, 2012 <?php echo form_label('User Select', 'user'); $options = array('0' => '- Select a User -',); foreach($users as $user): $options = $options + array($user->user_id => $user->user_name); endforeach; echo form_dropdown('user', $options); ?> ?> Quote Link to comment https://forums.phpfreaks.com/topic/258852-dropdown/#findComment-1327001 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.