Jump to content

how do i get only one question and related answer in codeigniter way ?


linux1880

Recommended Posts

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 ?

 

Link to comment
Share on other sites

  • 2 weeks later...

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.