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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:43:51+00:00 2026-05-20T15:43:51+00:00

I have the following tables with these attributes: location – location_id, name schedule –

  • 0

I have the following tables with these attributes:

location – location_id, name

schedule – schedule_id, name

locatoin_schedule – location_id, schedule_id

I am using a query like this.

SELECT l.name as locationName, s.name as scheduleName
FROM location AS l, schedule AS s, location_schedule AS ls
WHERE ls.schedule_id = s.schedule_id
AND ls.location_id = l.location_id

This is returning an array that looks like this:

Array
(
    [0] => stdClass Object
        (
            [locationName] => testing
            [scheduleName] => New Schedule
        )

    [1] => stdClass Object
        (
            [locationName] => another
            [scheduleName] => New Schedule
        )

    [2] => stdClass Object
        (
            [locationName] => testing
            [scheduleName] => Another Schedule
        )

)

Is it possible to have this return a multidimensional array of schedules if a location has many schedules as is the case with the testing location? So my intended outcome will be an array with only 2 indexes, rather than 3… but the testing locationName will contain an array with two schedules.

I hope this makes sense, thanks for your answer.

  • 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-20T15:43:52+00:00Added an answer on May 20, 2026 at 3:43 pm

    You’re stuck either processing the current query into the datastructure you want, or using GROUP_CONCAT and then splitting the schedules string into the structure you want. I’d stick with the first because it’s cleaner and the query is faster.

    $q="
    SELECT l.name as locationName, s.name as scheduleName 
    FROM location AS l JOIN schedule AS s ON ls.schedule_id = s.schedule_id 
     JOIN location_schedule AS ls
      ON ls.location_id = l.location_id";
    $r=$db->query($q)
    while($arr=$r->fetch_assoc()){
      $data[$arr['locationName']][]=$arr['scheduleName'];
    }
    

    or the GROUP_CONCAT option:

    $q="
    SELECT l.name as locationName, GROUP_CONCAT(s.name) as scheduleName 
    FROM location AS l JOIN schedule AS s ON ls.schedule_id = s.schedule_id 
     JOIN location_schedule AS ls
      ON ls.location_id = l.location_id
    GROUP BY locationName";
    $r=$db->query($q)
    while($arr=$r->fetch_assoc()){
      $schedules=explode($arr['scheduleName']);
      $data[$arr['locationName']]=$schedules
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML structure like the following: <tables> <table name=tableName1> <row ID=34 col1=data
I have the following tables, with these keys in my database: bookings session_id sessions
I have the following tables: users +----------+----------+----------+ | id | name | dob |
I have the following tables. I want to run a query but I think
I have the following tables in SQL Server 2005 ReceiptPoint: ID (PK), Name GasIndexLocation:
Assume I have the following tables and relationships: Person - Id (PK) - Name
I have following tables: products - 4500 records Fields: id, sku, name, alias, price,
I have two tables in MySQL that I'm comparing with the following attributes: tbl_fac
Is there any name for the following DB table design: Basically we have generic
I have following tables questions -> id, question_data, user_id users -> id, fname, lname

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.