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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:35:01+00:00 2026-06-13T20:35:01+00:00

mySql outputs this: As you can see row 3 and 4 has duplicates so

  • 0

mySql outputs this:
enter image description here

As you can see row 3 and 4 has duplicates so I want to merge these duplicates when I output my Json. To be exact I want my json to be like this:

[
    {
        "name": "The Crane Bar",
        "lat": "53.2692",
        "lng": "-9.06151",
        "events": [
            {
                "name": "Traditional music session",
                "info": null
            }
        ]
    },
    {
        "name": "Taaffes Bar",
        "lat": "53.2725",
        "lng": "-9.05321",
        "events": [
            {
                "name": "6 Nations, Italy VS Ireland",
                "info": null
            }
        ]
    },
    {
        "name": "a house",
        "lat": "37.4401",
        "lng": "-122.143",
        "events": [
            {
                "name": "Party at Palo Alto",
                "info": "Some info about the party"
            },
            {
                "name": "2gdfgdf",
                "info": "2gdfgdfgdf"
            }
        ]
    }
]

You know use one one location_name, lat and lng and have nested the event_name and post_content (as info here).

Thanks!

  • 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-13T20:35:04+00:00Added an answer on June 13, 2026 at 8:35 pm

    Based on your comment, you want the results to be nested, so when you generate the JSON, iterate over the rows and build a nested result list in PHP:

    $result = array();
    $item = null;
    
    for ($i = 0; $i < count($rows); ++$i) {
      $row = $rows[$i];
    
      if ($item === null) {
        $item = array('location' => $row['location'], 'events' => array());
      }
    
      $item['events'][] = array('name' => $row['event_name']);
    
      if ($i == count($rows) - 1 || $row['location'] != $rows[$i + 1]['location']) {
        $result[] = $item;
        $item = null;
      }
    }
    
    echo json_encode($result);  // JSON-encoded data
    

    Now each location will have an events list with one or more entries.

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

Sidebar

Related Questions

I'm logging output with log = /var/log/mysql/query.log and this works ok, but I only
I'm using following code but cannot return data from MySQL. This is the output:
I want to run a mysql command and set the output of that to
Using Python2.4 I want to capture output from a mysql command. One caveat is
How can i return my output in ArrayCollection? values = array(); while($row = mysql_fetch_array($result))
I query my mySql database table and retrieve text strings that look like this:
I have recordsets in my MySQL database like this (in german): Karrieren im Portrait:
This tail -n 1217060 input.sql > /disk2/mysql_dump/output.sql is not writing to the output file.
I need to create pdf document which outputs all rows from mysql table, but
Im not sure how to output MySQL data into formats below. (eg: timelist, usersex,

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.