TheJackal84 Posted September 21, 2017 Share Posted September 21, 2017 I have a member setting to allow the choice of multiple member selections $form->add( new \IPS\Helpers\Form\Member( 'mySetting', NULL, TRUE, array('multiple' => 10) ) ); How would I add the member_id values to the database? When multiple IS NOT selected or just set to 1 I can do it via \IPS\Db::i()->insert( 'my_table', array( 'MyDatabase' => $values['mySetting']->member_id ) ); But IF multiple is enabled it throws a error Link to comment Share on other sites More sharing options...
Adriano Faria Posted September 21, 2017 Share Posted September 21, 2017 You have to use explode( ‘,’, $field ) or add one member per row in a foreach. Link to comment Share on other sites More sharing options...
TheJackal84 Posted September 21, 2017 Author Share Posted September 21, 2017 10 minutes ago, Adriano Faria said: You have to use explode( ‘,’, $field ) or add one member per row in a foreach. I tried the explode but got no joy from it. I thought I might have to make a new table for the member_ids to store, a bit like how the map_user_id table is for messages, but was hoping I could just throw a array in the same column Link to comment Share on other sites More sharing options...
Adriano Faria Posted September 21, 2017 Share Posted September 21, 2017 I’m on phone now, can’t do much. Such for the member field that stores the users eho can promote items in ACP. It has an explode by “\n”, so it will store member IDs like that: 1 20 55 etc. in same column. Link to comment Share on other sites More sharing options...
TheJackal84 Posted September 21, 2017 Author Share Posted September 21, 2017 3 minutes ago, Adriano Faria said: I’m on phone now, can’t do much. Such for the member field that stores the users eho can promote items in ACP. It has an explode by “\n”, so it will store member IDs like that: 1 20 55 etc. in same column. Alright thanks, I gotta drop my kid to school now anyway so will check on it a bit later Link to comment Share on other sites More sharing options...
newbie LAC Posted September 21, 2017 Share Posted September 21, 2017 if ($values = $form->values(true)) // Set true and all values would be strings and \IPS\Db::i()->insert( 'my_table', array( 'some_column' => $values['mySetting'] ) ); Link to comment Share on other sites More sharing options...
TheJackal84 Posted September 21, 2017 Author Share Posted September 21, 2017 1 hour ago, newbie LAC said: if ($values = $form->values(true)) // Set true and all values would be strings and \IPS\Db::i()->insert( 'my_table', array( 'some_column' => $values['mySetting'] ) ); Perfect but it will add it in new lines like adriano shows above, How would I do it so it goes 1, 2, 3, 4 instead of 1 2 3 4 --- EDIT --- I done it, Thanks @Adriano Faria and @newbie LAC for the help I finished it off with the code below (If anyone else needs this in the future) $test = $values['mySetting']; $tester = is_array( $test ) ? implode( ",", $test ) : $test; $tester = implode(",", explode("\n", $tester)); then to the database \IPS\Db::i()->insert( 'my_table', array( 'some_column' => $tester ) ); Link to comment Share on other sites More sharing options...
newbie LAC Posted September 21, 2017 Share Posted September 21, 2017 8 minutes ago, TheJackal84 said: but it will add it in new lines like adriano shows above, What's wrong? In your code you can use explode("\n", $ids) instead of explode(",", $ids) If you prefer commas \IPS\Db::i()->insert( 'my_table', array( 'some_column' => implode(',', explode("\n", $values['mySetting'])) ) ); Link to comment Share on other sites More sharing options...
TheJackal84 Posted September 21, 2017 Author Share Posted September 21, 2017 2 minutes ago, newbie LAC said: What's wrong? In your code you can use explode("\n", $ids) instead of explode(",", $ids) If you prefer commas \IPS\Db::i()->insert( 'my_table', array( 'some_column' => implode(',', explode("\n", $values['mySetting'])) ) ); I managed to do it I edited my post above with how, Thanks again Link to comment Share on other sites More sharing options...
Adriano Faria Posted September 21, 2017 Share Posted September 21, 2017 1 hour ago, Adriano Faria said: I’m on phone now, can’t do much. Such for the member field that stores the users eho can promote items in ACP. It has an explode by “\n”, so it will store member IDs like that: 1 20 55 etc. in same column. You already made it but I will post it here; it may help anyone else someday. $form->add( new \IPS\Helpers\Form\Member( 'promote_members', \IPS\Settings::i()->promote_members ? array_map( array( 'IPS\Member', 'load' ), explode( "\n", \IPS\Settings::i()->promote_members ) ) : NULL, FALSE, array( 'multiple' => NULL ), NULL, NULL, NULL, 'promote_twitter_members' ) ); Save it like newbie_lac said. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.