Poll Query - 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: Poll Query (/showthread.php?tid=24381) |
Poll Query - El Forum - 11-08-2009 [eluser]amipaxs[/eluser] hi, I'm creating a dynamic poll using two tables table POLL fields(id,question,date) OPTIONS fields(id,option,votes,id_poll) now in my model Code: function displayPoll(){ controller : Code: $data['poll'] = $this->MPoll->displayPoll(); view : Code: if(count($poll)){ Severity: Notice Message: Undefined index: question Filename: views/poll_box.php Line Number: 13 I can see the options values correctly but not the the values outside the foreach loop, how do i extract them from the result set. Poll Query - El Forum - 11-08-2009 [eluser]wowdezign[/eluser] I don't know if this is the problem but I noticed in your model you have: Code: $this->db->orderby('poll.id', 'DESC'); and I think it should be: Code: $this->db->order_by('poll.id', 'DESC'); Poll Query - El Forum - 11-08-2009 [eluser]wowdezign[/eluser] Are you wanting to get the question, the possible answers, or both? Poll Query - El Forum - 11-08-2009 [eluser]amipaxs[/eluser] thanks i had not noticed that about orderby was working ok even when order_by is the correct.. i noticed another problem, I can't get the last poll question that i saved on the table, should i use date instead to get the last record.'? Poll Query - El Forum - 11-08-2009 [eluser]wowdezign[/eluser] This should get you one row from the database and return it. Code: function displayPoll(){ If you want the possible answers, you could run another query using the id to get the answers. Poll Query - El Forum - 11-09-2009 [eluser]amipaxs[/eluser] considering i'd make two queries one for the questions and another for the options how can i pass the poll id into the displayOptions function, i must extract the id from the array $data['poll'] , how ? $data['poll'] = $this->MPoll->displayPoll(); // $data['options'] = $this->MPoll->displayOptions(????); Poll Query - El Forum - 11-09-2009 [eluser]wowdezign[/eluser] Code: considering i’d make two queries one for the questions and another for the options How about: Code: $data[‘poll’] = $this->MPoll->displayPoll(); Once you have the object stored in a variable, you can access its properties. In this case, $data is an array, the array key 'poll' refers to an object that has an id property. So, $data['poll']->id should work. You have to be aware of what you are returning from your model. If it is an array, you'll need to do: Code: $data[‘poll’] = $this->MPoll->displayPoll(); instead. |