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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:48:52+00:00 2026-06-19T03:48:52+00:00

In my farming related Android app user sends crop’s name to PHP webservice and

  • 0

In my farming related Android app user sends crop’s name to PHP webservice and that webservice should return details about that crop.

Here’s the sample structure of database.

Crop_Master:Crop_Id , Crop_Name , Seed_Rate , Fertilizer
Pest: Crop_id , Pest_Name

Now I know about fetchAll() function of PDO and convert it to JSON array if the data is coming from a single table.

Like this: Here data comes from Crop_Master table and works fine.

$query1="select seed_rate,fertilizer_dosage from crop_master where crop_id='$crop_id'";

$res=$db->query($query1);

$output=$res->fetchAll(PDO::FETCH_ASSOC);

print(json_encode($output));

But I don’t know how I can create a single “output” array when the data is coming from multiple tables.

Suppose I want to create a JSON array like this:

[
   {
      "seed_rate":"value_from_db"
      "fertilizer":"value_from_db"
      "pests":
              [{"pest_name:"value_from_db"}
               {"pest_name:"value_from_db"}
                .
                .
                .
               ]
    }
]

Then how can I run multiple queries and make a single output array?

  • 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-19T03:48:52+00:00Added an answer on June 19, 2026 at 3:48 am

    You need to add array element “pests” to the array $output and populate it… How, will depend on the database structure, but likely something like

    $query1="select seed_rate,fertilizer_dosage from crop_master where crop_id='$crop_id'";    
    $res=$db->query($query1);    
    $output=$db->fetchAll(PDO::FETCH_ASSOC);
    
    $query2="select pest_name from pests, crop_pests where pests.pest_id = crop_pests.pest_id and crop_pests.crop_id='$crop_id'";    
    $res=$db->query($query2);    
    $output["pests"]=$db->fetchAll(PDO::FETCH_ASSOC);
    
    print(json_encode($output));
    

    So, point is, you need to have array of pests as element of your $output array. My $query2 is of course just an example and needs to be adjusted for your database

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

Sidebar

Related Questions

Having trouble framing this assertion in Rspec for my rails app. A User has
<span> <label for=305> <input type=checkbox name=305 style=vertical-align: middle; value=305 id=305> Farming General </label> </span>
I am having some trouble writing an algorithm that returns all the paths forming
I am needing help forming a jquery selector to return elements which are missing
I'm having trouble forming my query for a user assessment table I have. Currently
I am new to Android, but i know somewhat in Java, and Java EE
I'm not sure if my question is related to this one or not. IE9
Im writing a server application for my iPhone app. The section of the server
I am trying to define a recursive construct like a task farming. Here, I
I'm working on a library where I'm farming various tasks out to some third-party

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.