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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:28:16+00:00 2026-06-01T12:28:16+00:00

I am having some issues printing out the subarray homemain=>image This is my JSON

  • 0

I am having some issues printing out the subarray homemain=>image

This is my JSON

{
   "_id": ObjectId("4f7d0b9638fc5dc54c000000"),
   "station": "hits",
   "homemain": {
     "image": "URL",
     "link": "URL LINK" 
  } 
}

As you can see under homemain it has image I want the word URL to be printed out on the page.

This is my PHP script

public function main($stationname)
    {
        // select a collection (analogous to a relational database's table)
         $collection = $this->db->Stations_Banner;

        // find everything in the collection
        $cursor = $collection->find(array("station"=>"hits"),array("homemain"));

        $test = array();
            // iterate through the results
            while( $cursor->hasNext() ) {
                $test[] = ($cursor->getNext());
            }
        //Print Results 
        return json_encode($test);

    }

then on my index.php page I call this

<?php
    $banner = $fetch->main("hits");
    echo $banner;       
?>

I have tried to use $banner->homemain->image I have also tried it like $banner->homemain[‘image’]

  • 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-01T12:28:17+00:00Added an answer on June 1, 2026 at 12:28 pm

    Instead of this:

    return json_encode($test);
    

    Just do this:

    return $test;
    

    You don’t need to json_encode that because you’re still working with it in php. Then in your index.php you can just do this:

    $banner = $fetch->main("hits");
    echo $banner[0]['homemain']['image'];
    

    I assume that you’ll also want to loop through the results instead of just showing the image for the first one, but you didn’t say you needed help with that, so I’m just echoing the first result here.

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

Sidebar

Related Questions

I'm having some issues with an asp.net implementation of this JQuery facebook style autocomplete
I'm having some issues with my code. This is probably due to some design
Having some issues getting this MPMoviePlayerViewController to work. I have two sample URLs pointing
I'm developing a Wordpress plugin, and I'm having some issues with $_SERVER['HTTP_HOST'] . This
Having some issues running my code local. I have host file setup like this:
Having some issues with C. I have this is my code: // First line
Having some issues deploying this. I've tried to deploy it twice now. Here's what
Having some issues trying to create a fixed header layout for this jsfiddle: http://jsfiddle.net/4xk4D/107/
Having some issues with strcpy... Getting this error: strcpy' : cannot convert parameter 2
Having some issues getting my head around the differences between UTF-8, UTF-16, ASCII and

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.