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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:38:56+00:00 2026-06-13T04:38:56+00:00

With help from others on here, I’ve got a nested loop on the go

  • 0

With help from others on here, I’ve got a nested loop on the go that pull a list of months from one sql table and then, for each of those months, it goes through an events table and pulls the respective events.

Table structures are along the lines of:

MonthTable

ID  | MonthShort |  MonthLong
1 | 2012Oct | October 2012
2 | 2012Sep | September 2012 

EventTable

ID | MonthID | Event | Guests | Adults | Children
1 | 1 | Wedding | 200 | 150 | 50
2 | 1 | Bar Mitzvah | 100 | 50 | 50
3 | 1 | Funeral | 100 | 50 | 50 
4 | 2 | Birthday | 50 | 30 | 20 
5 | 2 | Birthday | 300 | 200 | 100
6 | 2 | Wedding | 200 | 180 | 20

My loop works so that it populates menu A with all available months, then populates menu B with all of the events for that month. You can then click on the event and it displays the relevant information – this is where I’m a bit stuck.

The arrays I’ve got are similar to the following, the guests array is what I’m trying out atm:

$events = array();
$months = array();
$guests = array();

while ($row = mysql_fetch_array($result)) {
  $months[$row["MonthID"]] = $row["MonthLong"];
  $events[$row["MonthID"]][] = $row["Event"];
  $guests[$row["MonthID"]][] = $row["Guests"];
}

I use a foreach to populate menu B with ($events[$x] as $event). The screen for each event will have an entry similar to the following and this is what I’d like to do (obviously I know this won’t work bu it should serve for illustrative purposes):

echo ‘ Number of guests: ‘ . print_r($guests[$x])

With guests and events both on the same counter I though it would allow me to print the array entry in the relevant position.

So what I’d like it if you click on “October 2012” and then select “Funeral“, the screen would say:

Number of guests: 100

There are actually several dozen records per event but no point going into all of them…

Apologies for the rambling and if this makes no sense! I’m new to PHP and am only really stuck on this bit.

SQL query is built on the following:

$sql = "
  SELECT
    a.id, b.id AS monthId, a.event, b.monthshort, b.monthlong
  FROM
    events_table_name AS a
  INNER JOIN
    month_table_name AS b ON b.id = a.monthId
  ORDER BY
    b.id, a.id ASC
  ";
  • 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-13T04:38:58+00:00Added an answer on June 13, 2026 at 4:38 am

    You need make use of the index in the foreach statement. I mean

    foreach ($events[$x] as $i => $event) {
        ...
        echo ' Number of guests: ' . print_r($guests[$x][$i]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Help from the SQL Gods Required Table 1 - DistinctQuotes This tables holds information
Just posting this here and might help the others: I got this error when
With help from you guys I now have a script that works like a
Without help from additional container (like vector), is it possible that I can make
With some help from SO, I have a bit of javascript/jquery that cycles through
cowboy coder needs some help from SO-veterans: I have a given application that uses
With some kindly help from StackOverflow, I've got Unity Framework to create my chained
Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded
This question is a little different from the others I've found here. My In
I've gotten help from others on this, but their replies were a little bit

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.