0

I'm trying to post the implode data of multiple select html to database but it is dynamic. Result will be like this:

data1|data2|data3 = from multiple select(already get)

how can I achieve this kind of result? It is separated with commas

data1|data2|data3, data1|data2|data3, data1|data2|data3

The separated data inside the commas come from another multiple select.

Here's my code HTML

<div class="required field">
  <label>Subjects:</label>
  <select class="ui fluid search dropdown" name="pass_subj[]" multiple="">
    <option value="">Subject</option>
    <option value="data1">subject1</option>
    <option value="data2">subject2</option>
    <option value="data3">subject3</option>
    <option value="data4">subject4</option>
    <option value="data5">subject5</option>
  </select>
</div>
<div class="two wide field" style="padding: 23px 0px 0px;">
  <button class="passmore ui icon yellow button" type="button">
    <i class="plus icon"></i>
  </button>
</div>

php

$pass_subj = $_POST['pass_subj'];
$pass_subjs = implode("|", $pass_subj);
Bry
  • 1
  • 3
  • 2
    More importantly - should you be doing this: https://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-bad. Alternatively, if you really want to store them in 1 field, look into using JSON instead. – Nigel Ren Dec 21 '22 at 10:56
  • you can simply concat using comma the result of your 3 implodes like this: `$implode1.', '. $implode2.', '.$implode3` – Bhavik Dec 21 '22 at 11:14
  • @Bhavik my multiple select is in array `pass_subj[]` – Bry Dec 21 '22 at 11:52
  • `The separated data inside the commas come from another multiple select` - which are these other multiple selects. For this I have mentioned to concat using comma – Bhavik Dec 21 '22 at 11:58

1 Answers1

0

I solved my own problem: My current project was using fomantic-ui; on my previous attempt, I used multiple select via select tag, which gives combined array values. To fix this, I used a dropdown via a div tag:

<div class="required field">
    <label>Subjects:</label>
     <div class="ui multiple selection dropdown clearable">
       <input name="pass_subj[]" type="hidden">
         <i class="dropdown icon"></i>
          <div class="default text">Subject</div>
           <div class="menu">
            <div class="item" data-value="AP">Araling Panlipunan</div>
            <div class="item" data-value="ENG">English</div>
            <div class="item" data-value="FIL">Filipino</div>
          </div>
     </div>
</div>
<div class="two wide field" style="padding: 23px 0px 0px;">
 <button class="passmore ui icon yellow button" type="button"><i class="plus icon"></i></button>
</div>      

My PHP:

$pass_subj = $_POST['pass_subj'];
                $pass_subjs = implode('#',$pass_subj);

The result will be:

AP#AP,ENG#AP,ENG,FIL#AP,FIL,MATH,ENG#AP,FIL,ENG,MATH,SCI
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Bry
  • 1
  • 3