Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6102557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:37:39+00:00 2026-05-23T13:37:39+00:00

my controller is $data[‘qna’] = $this->Ivote_model->get_qa(); view foreach($qna as $k=>$v){ echo $v[‘question’]. ‘<br/>’; echo

  • 0

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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:37:40+00:00Added an answer on May 23, 2026 at 1:37 pm

    I would do a couple of things:

    function get_qa(){
        /* ... */
    
        if($q->num_rows > 0){
            foreach($q->result_array() as $row){
                // create an associative array of question => answer.
                // that ensures 1-1 mapping.
                if(!isset($data[$row['question']])) $data[$row['question']] = array();
                $data[$row['question']][] = $row['answer'];
            }
        }
        /* ... */
    }
    

    Then, in the view:

     foreach($qna as $k=>$v){
        echo $k. '<br/>';
        foreach( $v as $ans ){ 
            echo '-' .$ans . '<br/>';
        }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to access the value of a view controller data member variables in
In previous releases there were 3 ways to pass data from controller to view
I'm passing data between my controller and my view using a ViewModel class. When
How can in controller redirect with post same data like this do form <form
I have a view controller that gets presented modally and changes some data that
I want to return the Model (data) of a controller in different formats (JavaScript/XML/JSON/HTML)
If I have posted to controller with data and save that data with... $this->Flo->save($this->data)
I'm trying to embed data I have defined in my controller in my view.
I have a question with respect to putting JSON data into a table view.
Many tutorials say that when i have to pass data from controller to view

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.