Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted September 21, 20177 yr 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
September 21, 20177 yr You have to use explode( ‘,’, $field ) or add one member per row in a foreach.
September 21, 20177 yr Author 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
September 21, 20177 yr 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.
September 21, 20177 yr Author 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
September 21, 20177 yr 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'] ) );
September 21, 20177 yr Author 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 ) );
September 21, 20177 yr 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'])) ) );
September 21, 20177 yr Author 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
September 21, 20177 yr 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.
Archived
This topic is now archived and is closed to further replies.