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

  • SEARCH
  • Home
  • 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 7601611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:12:25+00:00 2026-05-30T23:12:25+00:00

I have function in my database class that returns the id of the people

  • 0

I have function in my database class that returns the id of the people that are from the a specific country such as spain. But for some reason I only get one value, but there are many people with the same country. here is the function:

Class DbAb {
private $db;

public function sameCountry($country) {

    $query = "SELECT id FROM users WHERE country = ? ";
    $stmt = $this->db->prepare($query);
    $stmt->bind_param("s",  $country);
    if ($stmt->execute()) {

        $stmt->bind_result($sameCountry);
        $stmt->fetch();

        return $sameCountry;
    }
    return false;
}



}

$sameC = new DbAb();

$samePeople = $sameC->samecountry("spain");

print_r($samePeople);

Does anyone know how to return an array of results? I have tried to define the variable as an array but still doesn’t work…

  • 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-30T23:12:26+00:00Added an answer on May 30, 2026 at 11:12 pm

    The bind_result($var) + fetch() inserts a single row into the $var variable.

    If you want to return an array of ids from your method, you need to first create an empty array, then for each row, insert into it.

    eg. replace this:

    $stmt->bind_result($sameCountry);
    $stmt->fetch();
    return $sameCountry;
    

    with this:

    $arr = array();
    $stmt->bind_result($id);
    while ( $stmt->fetch() ) {
        $arr[] = $id;
    }
    return $arr;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that gets a value from the database and returns it.
I have a function that pulls rows from a database, the content->id and content->type
I have the following function that is pulling data from a database. The ajax
I have got this function that returns a constant..Here is my class and function:
I have a library function that returns a list of domain objects from a
I have a class that returns all items in a database table (Code below).
I have a class that performs database operations and returns results (array, true, false).
I have a DBAdmin class that connects to the database, and then some other
i have DataBase function that calculate distance by coordinates CREATE OR REPLACE FUNCTION distance(lat1
I have a function which calculates distance from database records. This function is called

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.