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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:36:22+00:00 2026-06-17T10:36:22+00:00

The code below works great for listing each class in rows and I’ve got

  • 0

The code below works great for listing each class in rows and I’ve got it sorted ASC from date and time BUT now I’d like to rearrange it so the classes that occur on Monday appear in order again by start time ASC in column one then continue the loop so classes that occur on Tuesday appear in column two and so on through the week. I’m not sure of the best method or even if I need to rewrite my foreach statements. I’ve tried switch using strings where each case would equal the days “Monday”, “Tuesday”, etc.

<table>
<tr>
<th width="80">Day</th>
<th width="80">Class</th>
<th width="80">Instructor</th>
<th width="80">Start</th>
<th width="80">End</th>
<th width="80">Studio</th>
</tr>
 <?php
 foreach ($data as $key => $row) 
 {
    $start_date[$key] = $row['Calendar']['start_date'];
    $start_time[$key] = $row['Calendar']['start_time']; 
 }
 array_multisort($start_date, $start_time, $data);

 foreach ($data as $row) {
  <tr>
  <td><?php $row['Calendar']['start_date']; ?></td>
  <td><?php $row['Calendar']['title']; ?></td>
  <td><?php $row['Calendar']['instructor']; ?></td>
  <td><?php $row['Calendar']['start_time']; ?></td>
  <td><?php $row['Calendar']['end_time']; ?></td>
  <td><?php $row['Calendar']['location']; ?></td>
  </tr>
  </table>

row list image

days in columns

my $data from mysql db when using SQL from Mike B.

 array(13) { 
    [0]=> array(2) { [0]=> array(1) { ["day_index"]=> string(1) "2" } ["calendars"]=> array(4) { ["title"]=> string(19) "Breakaway (Erin K.)" ["start_time"]=> string(8) "12:15:00" ["end_time"]=> string(8) "13:00:00" 

["location"]=> string(28) "Studio 1" } } 
[1]=> array(2) { [0]=> array(1) { ["day_index"]=> string(1) "2" } ["calendars"]=> array(4) { ["title"]=> string(20) "Breakaway (Cindy B.)" ["start_time"]=> string(8) "16:30:00" ["end_time"]=> string(8) "17:15:00" 

["location"]=> string(28) "Studio 1" } } 
[2]=> array(2) { [0]=> array(1) { ["day_index"]=> string(1) "2" } ["calendars"]=> array(4) { ["title"]=> string(20) "Breakaway (Larry N.)" ["start_time"]=> string(8) "18:15:00" ["end_time"]=> string(8) "19:00:00" 

["location"]=> string(28) "Studio 1" } } 
[3]=> array(2) { [0]=> array(1) { ["day_index"]=> string(1) "3" } ["calendars"]=> array(4) { ["title"]=> string(20) "Breakaway (Megan S.)" ["start_time"]=> string(8) "06:45:00" ["end_time"]=> string(8) "07:30:00" 

["location"]=> string(28) "Studio 1" } } 
[4]=> array(2) { [0]=> array(1) { ["day_index"]=> string(1) "3" } ["calendars"]=> array(4) { ["title"]=> string(20) "Breakaway (Larry N.)" ["start_time"]=> string(8) "11:15:00" ["end_time"]=> string(8) "12:00:00" 

["location"]=> string(28) "Studio 1" } } 
[5]=> array(2) { [0]=> array(1) { ["day_index"]=> string(1) "3" } ["calendars"]=> array(4) { ["title"]=> string(19) "Breakaway (Lisa G.)" ["start_time"]=> string(8) "17:30:00" ["end_time"]=> string(8) "18:15:00" 

["location"]=> string(28) "Studio 1" } } 
[6]=> array(2) { [0]=> array(1) { ["day_index"]=> string(1) "4" } ["calendars"]=> array(4) { ["title"]=> string(20) "Breakaway (Megan S.)" ["start_time"]=> string(8) "16:30:00" ["end_time"]=> string(8) "17:15:00" 

["location"]=> string(28) "Studio 1" } } 
[7]=> array(2) { [0]=> array(1) { ["day_index"]=> string(1) "4" } ["calendars"]=> array(4) { ["title"]=> string(19) "Breakaway (Lisa G.)" ["start_time"]=> string(8) "12:15:00" ["end_time"]=> string(8) "13:00:00" 

["location"]=> string(28) "Studio 1" } } 
[8]=> array(2) { [0]=> array(1) { ["day_index"]=> string(1) "5" } ["calendars"]=> array(4) { ["title"]=> string(21) "Breakaway (Lauren M.)" ["start_time"]=> string(8) "06:45:00" ["end_time"]=> string(8) "07:30:00" 

["location"]=> string(28) "Studio 1" } } 
[9]=> array(2) { [0]=> array(1) { ["day_index"]=> string(1) "5" } ["calendars"]=> array(4) { ["title"]=> string(19) "Breakaway (Adam A.)" ["start_time"]=> string(8) "11:15:00" ["end_time"]=> string(8) "12:00:00" 

["location"]=> string(28) "Studio 1" } } 
[10]=> array(2) { [0]=> array(1) { ["day_index"]=> string(1) "5" } ["calendars"]=> array(4) { ["title"]=> string(20) "Breakaway (Cindy B.)" ["start_time"]=> string(8) "17:30:00" ["end_time"]=> string(8) "18:15:00" 

["location"]=> string(28) "Studio 1" } } 
[11]=> array(2) { [0]=> array(1) { ["day_index"]=> string(1) "6" } ["calendars"]=> array(4) { ["title"]=> string(19) "Breakaway (Adam A.)" ["start_time"]=> string(8) "16:30:00" ["end_time"]=> string(8) "17:15:00" 

["location"]=> string(28) "Studio 1" } } 
[12]=> array(2) { [0]=> array(1) { ["day_index"]=> string(1) "7" } ["calendars"]=> array(4) { ["title"]=> string(20) "Breakaway (Rotation)" ["start_time"]=> string(8) "09:35:00" ["end_time"]=> string(8) "10:35:00" 

["location"]=> string(28) "Studio 1" } } } 

SQL

SELECT DAYOFWEEK(start_date) as day_index, title, start_time, end_time, location FROM calendars WHERE calendar_category_id = '3' AND location = 'Studio 1' ORDER BY day_index

got it by:

$calendar = array(); 
foreach ($data as $row) { 
$calendar[$row[0]['day_index']][] = $row;
}
  • 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-17T10:36:23+00:00Added an answer on June 17, 2026 at 10:36 am

    Are you getting this data from a database? If so you might want to consider changing up your query to get this different grouping. Perhaps something like this:

    SELECT DAYOFWEEK(date_field) AS day_index, [... other class fields ...]
    FROM table
    ORDER BY day_index ASC;
    

    Then you could read your data into a two-dimensional array like this:

    $calendar = array();
    while ($row = $db_result->fetch() ) { // or whatever you use to iterate through the result set.
        $calendar[$row['day_index']][] = $row;
    }
    

    This gives you an array like this:

    Array(
        '1' => Array(
             0 =>  Array(
                 'day_index' =>  '1',
                 ... other class fields ...
             ),
             1 =>  Array(
                  'day_index' => 1,
                 ... other class fields ...
             ),
             ... other class arrays from the result set ...
             ),
        '2' => ... Another numerically indexed array of class arrays for Monday classes ...
        '3' => ... Another numerically indexed array of class arrays for Tuesday classes ...
        ... and so on
    )
    

    Then it comes down to how you are displaying your data. I would think that in order to do what you want to do, you might need to go away from the table based layout you have and instead go with something like floated columns.

    This might look like this::

    <?php
    $days_of_week = array(
        '1' => 'Sunday',
        '2' => 'Monday',
        // etc.
    );
    ?>
    <div style="overflow: auto;">
    <?php foreach ($calendar as $day_index => $classes) { ?>
        <div style="width: 150px; margin: 5px; float: left;">
            <div style="margin: auto;"><?php echo $days_of_week[$day_index]; ?></div>
            <?php foreach ($classes as $class) {?>
                <div style="width:150px">
                <!-- class info here -->
                </div>
            <?php } ?>
        </div>
    <?php } ?>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code below works great. I have a MySQL database that contains book titles
The code below works great except the email has all the text on one
I have to code below - works great in IE and Opera, but does
Below is the code I have for sending email which works great. /* *
I'm really thrilled, because my code works great for me (se below), however I
The code below works great. If the Get and Use methods are in different
The code below works great. It prints out items in a MySQL database as
The code below works great. It allows a user to send emails to other
I've the code below that works great in my ready function in jquery, when
I have the following code below. Which works great expect I want to allow

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.