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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:37:55+00:00 2026-06-12T06:37:55+00:00

Ok this might get confusing cos I have not totally worked out how to

  • 0

Ok this might get confusing cos I have not totally worked out how to explain this perfectly but i’ll just show code to explain better than i could in words.

Basic idea: I am trying to collect all relevant data from queries assign it to a PHP variable then return it via json.encode for use on the site where ever needs be in Javascript.

So this is an example of what i am trying to do:

$stmt = $pdo->prepare("SELECT * FROM users WHERE uid= ?");
try {
    $stmt->execute(array($uid));
} catch (PDOException $e) {
    echo $e -> getMessage();  exit;
}

if(!$stmt->rowcount()){
    return false; exit;
}

$data = $stmt->fetchAll(PDO::FETCH_ASSOC); 

So i display $data at this point and i get this result:

Array ( 
  [0] => Array (
            [uid] => 1 
            [pass] => *****
            [show_name] => Dave
            [email] => test@test.com
  ) )

This is what i expected to occur 🙂

Next i want to add more results from queries to “$data”. Like so:

    $stmt = $pdo->prepare("SELECT * FROM databank WHERE uid=?");
    try{
        $stmt->execute(array($uid));
    } catch (PDOException $e){
        echo $e -> getMessage();  exit;
    }   
$data .= $stmt->fetchAll(PDO::FETCH_ASSOC);

This is where it goes wrong… when i echo/print_r $data at this point the result is:

 ArrayArray

Can some one explain why this occurs ? And how i solve it please 🙂

Thank you for your time!

  • 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-06-12T06:37:56+00:00Added an answer on June 12, 2026 at 6:37 am

    You’re concatenating each result to $data as though the results were strings, but they’re arrays; when forced to represent an array as a string, PHP produces ‘Array’, which is not what you want.

    Before your first line, do

     $data = array();
    

    and in place of your last line, do

     $data[] = $stmt->fetchAll(PDO::FETCH_ASSOC)
    

    and you should get

    Array ( 
      [0] => Array (
                [uid] => 1 
                [pass] => *****
                [show_name] => Dave
                [email] => test@test.com
      ),
      [1] => Array (
                [uid] => 2
                [pass] => *****
                [show_name] => Joe
                [email] => test@test.com
      ),
      [...]
    )
    

    in $data.

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, I might make this confusing, but hopefully not. So I have a UITableView
This might get a bit confusing and I'm not sure if it's possible, but
This might get a little confusing as I have tried everything to make this
This might be a trivial question, but I have not found anything about it,
I expect this might get some downvotes / closevotes but I'm going to ask
This might sound daft but how do you get silverlight to run as a
This might seam like a strange question but.... public string MyProperty { get {
This might sound like a stupid question but just trying to learn something here.
This might have to be broken down a bit but what i want to
This might be confusing but what I want to do is a basic select

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.