0

employer_rgn.php

<div class="form-group">
  <label for="" class="control-label col-xs-2">
    <?php echo $this->lang->line('spclzd_ctgry'); ?>
  </label>
  <div class=" col-md-8">            
    <input type="checkbox" name="spec_cat[]" value="Information Technology"> Information Technology 
    <input type="checkbox" name="spec_cat[]" value="Engineering / Manufacturing">Engineering / Manufacturing <br />
    <input type="checkbox" name="spec_cat[]" value="Banking & Financial Services"> Banking & Financial Services  
    <input type="checkbox" name="spec_cat[]" value="BPO / ITES"> BPO / ITES <br />
    <input type="checkbox" name="spec_cat[]" value="FMCG / Retail"> FMCG / Retail  
    <input type="checkbox" name="spec_cat[]" value="Telecom / ISP"> Telecom / ISP <br />
    <input type="checkbox" name="spec_cat[]" value="Pharmaceuticals / Health Care"> Pharmaceuticals / Health Care  
    <input type="checkbox" name="spec_cat[]" value="Sales & Marketing"> Sales & Marketing <br />
    <input type="checkbox" name="spec_cat[]" value="Other Non IT"> Other Non IT
  </div>
</div>

employer_model

public function insert()
{
  //Insert second stage details for employer into database.
  $Specilized_category = $this->input->post('spec_cat');
  $data=array('Specilized_category'=>implode(",", $Specilized_category),);
  $this->db->insert('tbl_employer', $data);

I'm inserting check box values into database separated by commas. But the problem is, I need to get back the checked values from database in order to edit my code. How could I get those values as I had used the implode method? Or do I have to change my code for inserting values into database?

1
  • You can simply explode that data using explode function in php Commented Sep 4, 2015 at 6:16

2 Answers 2

2

when you implode it create an array so its type can be array when it try to insert in to mysql. but you can store multiple values after converting in to string or json string.

Like...

public function insert()
{
    //Insert second stage details for employer into database.
    $Specilized_category = $this->input->post('spec_cat');
    $data=array(
    'Specilized_category'=>json_encode(implode(",", $Specilized_category)),
);
$this->db->insert('tbl_employer', $data);

Try it and let me know if you facing any problem while inserting.. ['}

Sign up to request clarification or add additional context in comments.

5 Comments

Insert worked well.. Thank you.. Now . , is it possible to get checked values in order to edit my form?
it always gives you in order values.Even you can check it after the implode like print_r(implode($specialized_category));
<input type="checkbox" name="spec_cat[]" value="Information Technology" <?php echo set_value('spec_cat[]', $row->Specilized_category) == 'Information Technology' ? "checked" : "";?>> Information Technology Is this work to get checked value as I'm tried for my radio button?
yes it works but please make sure with your condition <input type="radio" value="" <?php echo (<condition>) ? 'checked="checked"' : '' ;?> name="" > Good Luck... ['}
I told you make sure with your condition... please check the condition and its value else both are same ... [ -_-]
0

this model gives the following error

A Database Error Occurred

Error Number: 1452

Cannot add or update a child row: a foreign key constraint fails (shubhttc_online.destination_route, CONSTRAINT destination_route_ibfk_2 FOREIGN KEY (to_id) REFERENCES departure_city (dep_id))

INSERT INTO destination_route (to_id) VALUES ('\"2,4,5\"')

Filename: C:/xampp/htdocs/shubhttc_online/system/database/DB_driver.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.