Hello .. I want to insert an array in ONE field in mysql database using PHP ..
this is work fine :
HTML :
anotherField :<input type="text" name="anotherField" />
fax :<input type="text" name="f[]" />
email :<input type="text" name="f[]" />
phone :<input type="text" name="f[]" />
PHP (I use CodeIgniter frame) :
<?php
function addCustomRow($tableName)
{
$arr = $this->input->post('f');
$field = implode("|", $arr);
$data = array(
'anotherField' => $this->input->post('anotherField'),
'field' => $field
);
$this->db->insert($tableName, $data);
}
?>
and I get data in mysql like this
fax|email|phone
BUT ..
My question is .. I want many arrays in the same field .. Like this :
fax|email|phont :br: fax|email|phone :br: fax|email|phone ..
I tried some thing like this :
Html :
Frist array :
fax :<input type="text" class="inp" name="f[0][0]" />
email :<input type="text" class="inp" name="f[0][1]" />
phone :<input type="text" class="inp" name="f[0][2]" />
Second array :
fax :<input type="text" class="inp" name="f[1][0]" />
email :<input type="text" class="inp" name="f[1][1]" />
phone :<input type="text" class="inp" name="f[1][2]" />
PHP :
<?php
function addCustomRow($tableName)
{
$arr = $this->input->post('f[]');
$field = implode(":br:", $arr);
$data = array(
'anotherField' => $this->input->post('anotherField'),
'field' => $field
);
$this->db->insert($tableName, $data);
}
?>
but it says Wrong [ Severity: Notice Message: Array to string conversion ] and I get data in mysql like this
array :br: array
EDIT :
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
name of cat : <input type="text" name="name" />
<!-- Fields -->
Fields //
Field 1 :
title of the filde : <input type="text" name="f[0][0]" />
type : <input type="text" name="f[0][1]" /> <!-- 1= text , 2= select , 3= textarea .. -->
default value : <textarea rows="8" cols="20" name="f[0][2]"> </textarea> <!-- if select type write value1::value2::value3 ... -->
Field 2 :
title of the filde : <input type="text" name="f[1][0]" />
type : <input type="text" name="f[1][1]" /> <!-- 1= text , 2= select , 3= textarea .. -->
default value : <textarea rows="8" cols="20" name="f[1][2]"> </textarea> <!-- if select type write value1::value2::value3 ... -->
Field 3 :
title of the filde : <input type="text" name="f[2][0]" />
type : <input type="text" name="f[2][1]" /> <!-- 1= text , 2= select , 3= textarea .. -->
default value : <textarea rows="8" cols="20" name="f[2][2]"> </textarea> <!-- if select type write value1::value2::value3 ... -->
and I can add any number of fields here ..
in database I want data inserted like this :
[nameOfBook|1|anyName :br: noOfPages|1|anyNo ]
and in the other cat like this for example :
[colorOfcar|2|red::black::green :br: price|1|anyPrice ]
any help ?
thanks in advance ..