Unexpected results in print_r |
[eluser]jshultz[/eluser]
I have a join I'm doing between two tables but i'm getting unexpected results from the query. I know it's returning something, though. here's my model: Code: function tasksByProjectId() { and then in the controller it's just a simple: Code: $data['tasksByProject'] = $this->Project_model->tasksByProjectId(); and in the view I put a: Code: <pre> just so i could see what was coming out. Now, here's the odd thing. Depending on whether or not I do a left or full join I'll get various amounts of empty rows from this code: Code: <table> What's going on? Here's what I get from the print_r: Code: Resource id #29Resource id #44Array
[eluser]JoostV[/eluser]
Your model should retrieve the query result before returning anything. Code: $query = $this->db->get(); If you use a left join query there is no need for a join query at all, is there? You could just as well do this: Code: $this->db->select('projectid');
[eluser]jshultz[/eluser]
when I added these two line: Code: $query = $this->db->get(); the print_r changed to this: Code: stdClass Object and none of the table code rendered and everything after it disappeared. according to the user guide I need something like this: Code: $this->db->select('*');
[eluser]JoostV[/eluser]
>according to the user guide I need something like this: Yes, but you need to generate the query result as well. Look here: http://ellislab.com/codeigniter/user-gui...sults.html In your view, loop through the result like this: Code: if (count($tasksByProject) > 0) {
[eluser]JoostV[/eluser]
In short. Model: Code: function tasksByProjectId() { Controller Code: $data['tasksByProject'] = $this->Project_model->tasksByProjectId(); View: Code: <table>
[eluser]jshultz[/eluser]
it's working! I have another question? How do i get the other columns to appear in the query result?
[eluser]jshultz[/eluser]
so i figured out what print_r was outputting. that was cool. I edited my query up some to retrieve additional columns: Quote:function tasksByProjectId() { but i'm still only receiving the projectid from the database when i updated my code to do this: Code: <pre> I tested the sql code in phpmyadmin and it's returning all the columns and rows, though. it's just not showing up on the page.
[eluser]JoostV[/eluser]
You have a space after the arrows on every row call Code: $row-> projectid Should be Code: $row->projectid
[eluser]jshultz[/eluser]
It didn't make any difference, it's still only echoing out the projectid: Code: <pre>
[eluser]jshultz[/eluser]
Ok, it's all working now. Thanks for your help. Here's what I ended up doing that worked: Code: function tasksByProjectId() { and here's the view: Code: <table> |
Welcome Guest, Not a member yet? Register Sign In |