Welcome Guest, Not a member yet? Register   Sign In
Multiple Values in Single Field in DB -> Seperate Values for CI
#1

[eluser]AndrewTurner[/eluser]
Hey Everyone,

I've been racking my brains as to how to store multiple values in a single field and have a db relationship setup, but that's just not working, So I'm moving it over to become part of my existing CI system.

I wanted to know if there's an easy way to get these values, seperate them based upon a comma and then check to see if they match another record stored in another table?

In my head, It's sounding rather complicated and I can't get my head around it.

Does anybody have any general ideas how to approach this, or any libraries that might be of use?
#2

[eluser]mddd[/eluser]
This will work, as long as your values don't contain commas and you don't want to search for them in your database.
For instance, if the info is a simple list of numbers
Code:
// write to db
$myvalues = array(1,2,3,4);
$this->db->set('value_field', join(',', $myvalues));
$this->db->insert('my_table');

// info is stored in column value_field as a string "1,2,3,4"

// read from db
$this->db->where('id', $some_id);
$data = $this->db->get('my_table')->row();
$myvalues = explode(',', $data->value_field);

// info is now back to an array: 1,2,3,4
#3

[eluser]AndrewTurner[/eluser]
Also I forgot to add, When selected from the front end they're put into an array/string and then prepared for insertion into the database.

Thanks for that, I will try it Smile




Theme © iAndrew 2016 - Forum software by © MyBB