Welcome Guest, Not a member yet? Register   Sign In
Unserialize data for inclusion in a csv string
#1

[eluser]Brad K Morse[/eluser]
v1.7.3

Code:
function exportCsv($venue_id) {
  $this->load->dbutil();
  $q = $this->db->select(
    'first_name, last_name, email, phone, contact_when, tshirt, thursday, friday, saturday, sunday, comments'
  )->where('venue_id',$venue_id)->order_by('last_name','asc')->get('data');
  
  return $this->dbutil->csv_from_result($q, ",", "\n");
}

Is it possible to unserialize the data of 4 fields (thursday, friday, saturday, sunday) with how it is set up now?
#2

[eluser]InsiteFX[/eluser]
Not sure about this, but you can find CodeIgniters serialize and unserialize
in the CodeIgniter Session library and the end of the file.

InsiteFX
#3

[eluser]carvingCode[/eluser]
>> Is it possible to unserialize the data of 4 fields (thursday, friday, saturday, sunday) with how it is set up now?

Don't know if you've solved this yet.

To unserialize a array element (which is what's coming out of the query, you've got to get to the element.

Before passing the result to the csv method, I would break the query result up into its components (use foreach to loop through), perform the unserialize function on the appropriate fields and store it back into the field. Then, pass the array to the csv function.

Code:
foreach ($query as $key => $value) {
  if ($key == 'matches one of your field locations') {
    $value = unserialize($value);
  }
}

Now pass $query to the csv function as normal.

Hope this helps.
#4

[eluser]Brad K Morse[/eluser]
Thanks for the solution.

I don't remember why I had all the values serialized to begin with, so I unserialized them, running a loop to print all the values into a update query, copy and pasted all those queries into Sequel Pro, ran all at once and it updated all the serialized values with the unserialized version of it and made the changes in the application to insert unserialized data to the db table from then on out.

I will bookmark this for future reference, thanks again!




Theme © iAndrew 2016 - Forum software by © MyBB