Welcome Guest, Not a member yet? Register   Sign In
[solved] Help needed for database results issue
#1

[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?
#2

[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.




Theme © iAndrew 2016 - Forum software by © MyBB