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 4607600
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:43:33+00:00 2026-05-22T00:43:33+00:00

My method returns an array of answers by mysqli_fetch_assoc. I try to extract the

  • 0

My method returns an array of answers by mysqli_fetch_assoc. I try to extract the answer according to the index. The result does not match expectations. I would get the same answers(should be three answers).

method:

function getAnswers($id_question)
{
    $sql = 'SELECT * FROM answers WHERE question_id = '. $id_question;

    $this->db->query($sql);
    while ($answers = $this->db->fetchAssoc())
    {
        return $answers;
    }
}

use:

$answers = getAnswers(1);
foreach($answers as $a)
{
    echo $a['answer'];
}
echo '<pre>';
print_r($answers);
echo '</pre>';

out:

11a1
Array
(
    [id_answer] => 1
    [question_id] => 1
    [answer] => answer 1
    [truth] => 1
)
  • 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-22T00:43:34+00:00Added an answer on May 22, 2026 at 12:43 am

    You are returning only the first set. You will have to pack the data into an array and then return the array:

    function getAnswers($id_question)
    {
        $sql = 'SELECT * FROM answers WHERE question_id = '. $id_question;
    
        $this->db->query($sql);
        $data = array();
        while ($answers = $this->db->fetchAssoc())
        {
            $data[] = $answers;
        }
    
        return $data;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method which returns an array of fixed type objects (let's say
I wish to create a java method that returns an array of type: ABCout,
I have a method (C++) that returns a character and takes an array of
I have a Ruby method that searches an array of hashes and returns a
What method returns a random int between a min and max? Or does no
Is their a method to have multiple right answers with the same result? function
For any given NSManagedObject, is there any method to return a set or array
ExecuteQuery() method returns an IEnumerable but is there a way to make it return
Javascript's getTime() method returns the number of milliseconds since midnight of January 1, 1970.
The Python datetime.isocalendar() method returns a tuple (ISO_year, ISO_week_number, ISO_weekday) for the given datetime

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.