linux1880 Posted July 7, 2011 Share Posted July 7, 2011 my controller is $data['qna'] = $this->Ivote_model->get_qa(); view foreach($qna as $k=>$v){ echo $v['question']. '<br/>'; echo '-' .$v['answer'] . '<br/>'; model function get_qa(){ $data = array(); $this->db->select('*'); $this->db->where('v_questions.id',1); $this->db->from('v_answers'); $this->db->join('v_questions','v_questions.id = v_answers.question_id'); $q = $this->db->get(); if($q->num_rows > 0){ foreach($q->result_array() as $row){ $data[] = $row; } } $q->free_result(); return $data; } my html page shows What is your favorite food? -Sushi What is your favorite food? -Burgers What is your favorite food? -kodo what i want is What is your favorite food? -Sushi -Burgers -koddo please help me how do i achieve that ? Quote Link to comment https://forums.phpfreaks.com/topic/241310-how-do-i-get-only-one-question-and-related-answer-in-codeigniter-way/ Share on other sites More sharing options...
gristoi Posted July 7, 2011 Share Posted July 7, 2011 just manipulate the array in the view: <?php echo $qna[0]['question']. '<br/>'; foreach($qna as $k=>$v){ echo '-' .$v['answer'] . '<br/>'; } ?> this is a guess as to your array structure by the way Quote Link to comment https://forums.phpfreaks.com/topic/241310-how-do-i-get-only-one-question-and-related-answer-in-codeigniter-way/#findComment-1239542 Share on other sites More sharing options...
linux1880 Posted July 7, 2011 Author Share Posted July 7, 2011 Thanks a lot , it is working for single question, bot not when i have multiple questions and answers. Could you pls give me a hint what am i missing ? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/241310-how-do-i-get-only-one-question-and-related-answer-in-codeigniter-way/#findComment-1239606 Share on other sites More sharing options...
rallport Posted July 21, 2011 Share Posted July 21, 2011 Thanks a lot , it is working for single question, bot not when i have multiple questions and answers. Could you pls give me a hint what am i missing ? Thanks Well if that's the case you may need some more intellegant loop logic. You could use a second loop, but that may get quite messy imo. Can you post your database structure? Quote Link to comment https://forums.phpfreaks.com/topic/241310-how-do-i-get-only-one-question-and-related-answer-in-codeigniter-way/#findComment-1245904 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.