CodeIgniter Forums
[solved] Help needed for database results issue - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: [solved] Help needed for database results issue (/showthread.php?tid=14647)



[solved] Help needed for database results issue - El Forum - 01-09-2009

[eluser]Charles Garrison[/eluser]
I have a function that pulls data from a database using the active record method - the code looks something like this...
Code:
$selected_db = $this->load->database( $this->confg, TRUE );

$selected_db->select( '*' );
$selected_db->from( 'table_name' );
$selected_db->where( 'zip', '87111' );

$query = $selected_db->get();

When I put this into a foreach loop, I am able to access the data like this...
Code:
foreach( $query->result() as $row ) {
  echo $row->name; //assuming name was one of the database fields
}

My problem is I want to modify some of this returned data AND keep it in the same format as it was so I can access it using the foreach loop / $row->... statement as detailed above. Everytime I do this, I lose the structure and end up with an array. Anyone know how to do this?


[solved] Help needed for database results issue - El Forum - 01-09-2009

[eluser]Charles Garrison[/eluser]
I figured it out...

Code:
foreach( $query->result() as $row ) {
  $row->name = $row->name . '_tag';
}

My code was much different and much more complex, but this is the same concept to demonstrate the answer to my question if anyone else needs to do this too.