New in codeigniter! poll problem - 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: New in codeigniter! poll problem (/showthread.php?tid=21866) |
New in codeigniter! poll problem - El Forum - 08-23-2009 [eluser]benfike[/eluser] Hi! I now work on a poll system. I make 2 sql table for this: #vote_answers -vote_id -answer_id -answer #vote_question -vote_id -question -status('active','inactive','finished') For Get answers I make an function with this name : Code: function getAnswers(){ And only want to list that answer where the vote_answers.vote_id = vote_question.vote_id How can i do this? My other problem: if i make some answers for a Question it list only 1! Code: <?php foreach($answers as $answer):?> New in codeigniter! poll problem - El Forum - 08-23-2009 [eluser]Dark Preacher[/eluser] There is an error in your function: Code: $data['answer'] = $row['answer']; Code: $data[] = array('answer' => $row['answer']); New in codeigniter! poll problem - El Forum - 08-23-2009 [eluser]benfike[/eluser] Its work, but my first problem still here :S New in codeigniter! poll problem - El Forum - 08-23-2009 [eluser]larsjeh[/eluser] [quote author="benfike" date="1251070481"]Its work, but my first problem still here :S[/quote] I think that you need a MySQL JOIN for this problem. I think this should help, for preventing that your array is printed on the screen, comment or remove print_r($data). Code: function getAnswers(){ New in codeigniter! poll problem - El Forum - 08-23-2009 [eluser]benfike[/eluser] Error Number: 1066 Not unique table/alias: 'votes_answers' SELECT * FROM (`votes_answers`, `votes_answers`) JOIN `votes` ON `votes`.`id` = `votes_answers`.`pid` update: when I delete that: $this->db->from('votes_answers'); the page work, but again list all answers, not only where vote_id = other vote_id New in codeigniter! poll problem - El Forum - 08-24-2009 [eluser]larsjeh[/eluser] [quote author="benfike" date="1251076276"]Error Number: 1066 Not unique table/alias: 'votes_answers' SELECT * FROM (`votes_answers`, `votes_answers`) JOIN `votes` ON `votes`.`id` = `votes_answers`.`pid` update: when I delete that: $this->db->from('votes_answers'); the page work, but again list all answers, not only where vote_id = other vote_id[/quote] Sry m8 made a mistake with $this->db->get , i think this should work. Code: function getAnswers(){ New in codeigniter! poll problem - El Forum - 08-24-2009 [eluser]benfike[/eluser] Dont work, I dont know now what is the problem..:S Now I add this but still dont work :/ Code: function getAnswers(){ Some table name new, because i changed something. #votes -id -name -status #votes_answers -id -pid (pollID) -answer -votes (for results) |