title: Insert array in ONE field in mysql
body: <p>I want to insert an array in ONE field in mysql database using PHP ..</p>
  
  <p>this is work fine :</p>
  
  <p>HTML :</p>
  
  <pre><code>anotherField :&lt;input type="text"  name="anotherField" /&gt;
  
  fax :&lt;input type="text"  name="f[]" /&gt;
  email :&lt;input type="text"  name="f[]" /&gt;
  phone :&lt;input type="text"  name="f[]" /&gt;
  </code></pre>
  
  <p>PHP (I use CodeIgniter frame) :</p>
  
  <pre><code>&lt;?php
      function addCustomRow($tableName)
      {
  
      $arr = $this-&gt;input-&gt;post('f');
      $field = implode("|", $arr);
  
          $data = array(
          'anotherField'          =&gt; $this-&gt;input-&gt;post('anotherField'),
          'field'             =&gt; $field
          );
  
          $this-&gt;db-&gt;insert($tableName, $data);
      }
  ?&gt;
  </code></pre>
  
  <p>and I get data in mysql like this</p>
  
  <pre><code>fax|email|phone
  </code></pre>
  
  <p><strong>BUT ..</strong></p>
  
  <p>My question is .. I want many arrays in the same field .. Like this :</p>
  
  <pre><code>fax|email|phone :br: fax|email|phone :br: fax|email|phone ..
  </code></pre>
  
  <p>I tried some thing like this  :</p>
  
  <p>Html :</p>
  
  <pre><code>First array :
  fax :&lt;input type="text" class="inp" name="f[0][0]" /&gt;
  email :&lt;input type="text" class="inp" name="f[0][1]" /&gt;
  phone :&lt;input type="text" class="inp" name="f[0][2]" /&gt;
  
  Second array :
  fax :&lt;input type="text" class="inp" name="f[1][0]" /&gt;
  email :&lt;input type="text" class="inp" name="f[1][1]" /&gt;
  phone :&lt;input type="text" class="inp" name="f[1][2]" /&gt;
  </code></pre>
  
  <p>PHP :</p>
  
  <pre><code>&lt;?php
      function addCustomRow($tableName)
      {
  
      $arr = $this-&gt;input-&gt;post('f[]');
      $field = implode(":br:", $arr);
  
          $data = array(
          'anotherField'          =&gt; $this-&gt;input-&gt;post('anotherField'),
          'field'             =&gt; $field
          );
  
          $this-&gt;db-&gt;insert($tableName, $data);
      }
  ?&gt;
  </code></pre>
  
  <p>but it says Wrong [ Severity: Notice Message: Array to string conversion  ]
  and I get data in mysql like this</p>
  
  <pre><code>array :br: array  
  </code></pre>
  
  <p><strong>EDIT :</strong></p>
  
  <p>I want to do that like this way because I have a Categories Table ..
  and each cat has own details ( fields ) .. so when I add new cat I just do some thing like this</p>
  
  <pre><code>       name of cat : &lt;input type="text"  name="name" /&gt;
  
     &lt;!-- Fields --&gt;
      Fields //
  
      Field 1 :
      title of the filde : &lt;input type="text"  name="f[0][0]" /&gt;
      type : &lt;input type="text"  name="f[0][1]" /&gt; &lt;!-- 1= text , 2= select , 3= textarea ..  --&gt;
      default value : &lt;textarea rows="8" cols="20" name="f[0][2]"&gt; &lt;/textarea&gt; &lt;!-- if select type write value1::value2::value3  ... --&gt;
  
  
  
  Field 2 :
  title of the filde : &lt;input type="text"  name="f[1][0]" /&gt;
  type : &lt;input type="text"  name="f[1][1]" /&gt; &lt;!-- 1= text , 2= select , 3= textarea ..  --&gt;
  default value : &lt;textarea rows="8" cols="20" name="f[1][2]"&gt; &lt;/textarea&gt; &lt;!-- if select type write value1::value2::value3  ... --&gt;
  
  Field 3 :
  title of the filde : &lt;input type="text"  name="f[2][0]" /&gt;
  type : &lt;input type="text"  name="f[2][1]" /&gt; &lt;!-- 1= text , 2= select , 3= textarea ..  --&gt;
  default value : &lt;textarea rows="8" cols="20" name="f[2][2]"&gt; &lt;/textarea&gt; &lt;!-- if select type write value1::value2::value3  ... --&gt;
  </code></pre>
  
  <p>and I can add any number of fields here ..</p>
  
  <p>in database I want data inserted like this :</p>
  
  <pre><code>[nameOfBook|1|anyName :br: noOfPages|1|anyNo ]
  </code></pre>
  
  <p>and in the other cat like this for example :</p>
  
  <p>[colorOfcar|2|red::black::green :br: price|1|anyPrice ]</p>
  
  <p>any help ?</p>
  
  <p>thanks in advance ..</p>
  
  <hr>
  
  <p>@Justin Johnson</p>
  
  <p>thanks for your answer, but it doesnt work.
  I have to use $data var to insert all the data but I use you answer like this</p>
  
  <pre><code>function addCustomRow($tableName)
  {
  
      $data = array(
          'name'          =&gt; $this-&gt;input-&gt;post('name'),
          'fields'            =&gt; serialize($this-&gt;input-&gt;post('f[]'))
          );
  
      $this-&gt;db-&gt;insert($tableName, $data);
  }
  </code></pre>
  
  <p>and I get data mysqyl like this ( b:0; ) !!</p>
  
  <p>//</p>
  
  <p>@Suku thanks .. I have used it before asking but I did not know how .. How can I use it in my case here ? .. </p>
  
  <p>@Alex</p>
  
  <p>because I have table named (categories) and every cat has own fields like :</p>
  
  <pre><code>carsCat &gt;
    type :
    color:
    details:
  
  BooksCat &gt;
  nameOfbook:
  writer:
  numberOfpage:
  </code></pre>
  
  <p>and so on ..
  I find this way the Best way maybe in my case .. any suggestions?</p>