Welcome Guest, Not a member yet? Register   Sign In
Store data data from multiple fields
#5

[eluser]Mangetsu[/eluser]
All you have to do to add new features is

Code:
$features = $this->input->post('feature', TRUE);

foreach($features as $key => $value)
{
$feature=array(
  'product_id'=>$this->input->post('product_id'),
  'feature_id'=>$key,
  'value'=>$value
);

$this->db->insert('product_features',$feature);

}

But this is so simple only if you do insert.. Update gets a bit complicated..Especially if you change feature number, ie. remove one of existing features. I usually do such things by getting all existing features of saved product, check in array if feature exists, if does I do update and remove it from that array. If doesn't I do insert. Remaining features in array are features that exist in DB but not in new data, so i remove them from DB. There's probably better way of doing it, I tend to complicate sometimes, but it's how I've done it in several cases.


Messages In This Thread
Store data data from multiple fields - by El Forum - 10-10-2013, 04:47 AM
Store data data from multiple fields - by El Forum - 10-10-2013, 09:17 AM
Store data data from multiple fields - by El Forum - 10-11-2013, 02:27 AM
Store data data from multiple fields - by El Forum - 10-12-2013, 02:00 AM
Store data data from multiple fields - by El Forum - 10-12-2013, 03:05 AM
Store data data from multiple fields - by El Forum - 10-12-2013, 03:31 AM
Store data data from multiple fields - by El Forum - 10-12-2013, 04:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB