Adding html Around a Table Column |
[eluser]thatguy142[/eluser]
Hello, I have a function that I'm using to generate a table based on a query run against the database. I want to add a link in each row in the "title" column for a user to click on to edit more details related to that row, but the returned table still doesn't get updated. Code: function create_table($table) { Is there something obvious that I'm missing here? Thanks.
[eluser]Aken[/eluser]
$row becomes a new variable that is only available during that iteration. In order to change the original array item, you must define it as a reference. Code: foreach ($query->result_array() as &$row) { ... http://php.net/manual/en/language.references.php
[eluser]thatguy142[/eluser]
Thanks for the suggestion. I tried that earlier today but I was getting this error when I did: "Fatal error: Cannot create references to elements of a temporary array expression" So I wasn't sure if that was the right way to go. I can tell that the changes are being made to a local copy of the array, I just can't figure out how to get the right array changed.
[eluser]thatguy142[/eluser]
The next thing I've tried is assigning the query result to a variable before the foreach like so: Code: $this->db->select('id, due_date, title, company, short_description'); The new error I'm getting is "Fatal error: Cannot use object of type stdClass as array" on this line: Code: $row['title'] = anchor('jobs/edit/'.$row['id'],$row['title']); . I think I'm on the right track and just need to figure out how to access the data properly.
[eluser]thatguy142[/eluser]
Ok. The thing I've realized is that $query->result() returns the result rows as objects. I've thus changed the last code bit to this: Code: $query = $this->db->get('jobs', $config['per_page'], $this->uri->segment(3)); This puts me back at the error: “Fatal error: Cannot create references to elements of a temporary array expression” And if I remove the & in front of row, I get a familiar error in the table library itself: "Fatal error: Cannot use object of type stdClass as array in C:\wamp\www\ci\system\libraries\Table.php on line 178"
[eluser]thatguy142[/eluser]
Sorry to clog up the forum with so many self-responses. I've solved the problem. I was mixing up the syntax between $query->result() and $query-result_array(). Here's the final solution: Code: $query = $this->db->get('jobs', $config['per_page'], $this->uri->segment(3)); I hope this helps someone in the future! |
Welcome Guest, Not a member yet? Register Sign In |