mheavers
mheavers

Reputation: 30158

code igniter php - unserialize an array

I have previously serialized an array in PHP and submitted it to a database. Now, in my model in Code Igniter, I want to unserialize that data but I'm not sure how to reference it.

Here's my code:

function get_selected_member($member = null){
    if($member != NULL){
        $this->db->where('id', $member); //conditions
    }
    $query = $this->db->get('members'); //db name

    if($query->result()){
        $member_result = $query->row();
        //log_message('info', $member_result[$member_result->member_dep]); //trying to find member_dep - how do I reference it?

        return $member_result;
    }
}

So member_result is an object containing all of values for the table row matching the member a user selected from a form. Within this object, one of the column values is member_dep - but referencing it as $member_result[$member_result->member_dep] does not work. How do I refer to this. I basically want to pull that value out, declare it as a variable, call unserialize(), and then put it back into place so that it can be read by JQuery / HTML as an array.

Upvotes: 2

Views: 4601

Answers (1)

user775263
user775263

Reputation: 246

You should be able to use

$member_dep = unserialize($member_result->member_dep);

Upvotes: 8

Related Questions