0

What to do if I want to add all the file names in single column in mysql database

$data = array(
    'name' => $this->input->post('pd_name'),
    'image' => $product_image,
    'image' => $product_image1,
    'image' => $product_image2,
    'created_time' => date('Y-m-d H:i:s')
);

this doesn't work

Atural
  • 5,389
  • 5
  • 18
  • 35
akku
  • 23
  • 8
  • your array doesn't make any sense - the key `image` just holds the name of `$product_image2` - what exactly is it what you want ? – Atural Jan 06 '18 at 10:12
  • I want to insert product_image,product_image1,product_image2, into a single column called "image" in my database – akku Jan 06 '18 at 10:49

1 Answers1

0

You can implode the variables while storing into a single column.

$image_data = array($product_image, $product_image1, $product_image2);
implode('#',$image_data);

when you want to display just explode them.

explode('#',$image_data);
Darshan Kini
  • 114
  • 8
  • thanks, its worked. but when i want to display them an error came, "Message: explode() expects parameter 2 to be string, array given" public function fetch_doc() { $id= $this->uri->segment(3); $doc=$this->user_model->fetch_doc($id); print_r (explode(',',$doc)); //$this->load->view('view_doc'); } public function fetch_doc($id) { $this->db->select('document'); $this->db->from('employee_details'); $this->db->where('id',$id); $query=$this->db->get(); return $query->result(); } this is my model – akku Jan 06 '18 at 15:11
  • suppose you get the result in the array $data which consist of all details. so you get image columns data. which is $data['image]=image_1#image_2#image_3. explode this using function. $image_data = explode('#',$data['image]); now you will get numeric array. use for loop you will get all images like $image_data[$i] – Darshan Kini Jan 06 '18 at 18:56
  • but this is how my array looks like "stdClass Object ( [document] => imran.jpg,rahul.jpeg,rizwan_(2).jpeg,safdar.jpg,,wahid.jpg )" – akku Jan 07 '18 at 05:29
  • return $result->result_array(); or else you need to remove std class object. https://stackoverflow.com/questions/16420384/remove-stdclass-objects-from-array – Darshan Kini Jan 07 '18 at 06:12
  • need to remove std class object, then only I can display these images in my view page,right? – akku Jan 07 '18 at 06:17
  • yep. once you remove it. It will be simple one value. explode it. you will get the numeric array. use foreach loop to get the images name – Darshan Kini Jan 07 '18 at 06:20