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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:47:24+00:00 2026-06-05T16:47:24+00:00

I’m grabbing a list of events from a database and am trying to associate

  • 0

I’m grabbing a list of events from a database and am trying to associate like dates with one header. As of the moment I’m using <dl> <dt> <dd>, etc as per request. This may change but I don’t think it impacts the overall impact of my question.

Basically I am trying to grab the 5 newest events via a query:

global $wpdb;

$sql = "SELECT e.*, c.*, ese.start_time, ese.end_time
        FROM wp_events_detail e
        JOIN wp_events_category_rel r ON r.event_id = e.id
        JOIN wp_events_category_detail c ON c.id = r.cat_id
        LEFT JOIN wp_events_start_end ese ON ese.event_id= e.id 
        WHERE e.is_active =  'Y'
        AND c.category_identifier = 'main'
        ORDER BY e.start_date ASC
        LIMIT 0, 5";
$results = $wpdb->get_results($sql);

I then loop them through a foreach():

if(count($results) > 0) {

    echo '<div class="calendar-list">';

    foreach($results as $event) {

        $event_id = $event->id;
        $event_name = $event->event_name;
        $start_date = $event->start_date;
        $start_time = $event->start_time;

        $start_time = strtotime($start_time);
        $start_time = date('g:ia', $start_time);

        $the_time =  strtotime($start_date);

        $the_day = date('d', $the_time);
        $the_month = date('M', $the_time);

        echo '<dl class="calendar-day first-child">';
        echo '<dt>';
        echo '<p class="the-month">' . $the_month . '</p>';
        echo '<p class="the-day">' . $the_day . '</p>';
        echo '</dt>';
        echo '<dd>';
        echo '<h4><a href="' . $event_id . '">' . $event_name . '</a></h4>';
        echo '<h5><span class="time">' . $start_time . '</span></h5>';
        echo '</dd>';
        echo '</dl>';

    }

    echo '</div>';
}

My main problem is I need to figure out a way to associate dates with one another. For example, June 27th. If there are two dates I would like it to look like:

<div class="calendar-list">
    <dl class="calendar">
        <dt>
            <p class="the-month">JUN</p>
            <p class="the-day">27</p>
        </dt>
        <dd>
            <h4><a href="#">Title</a></h4>
                        <h5><span class="time">Time</span></h5>
        </dd>
        <dd>
            <h4><a href="#">Title</a></h4>
                        <h5><span class="time">Time</span></h5>
        </dd>
    </dl>
    <dl class="calendar">
        <dt>
            <p class="the-month">JUN</p>
            <p class="the-day">28</p>
        </dt>
        <dd>
            <h4><a href="#">Title</a></h4>
                        <h5><span class="time">Time</span></h5>
        </dd>
        </dl>
</div>

I am quite unsure how to achieve this. I have been playing around with setting and unsetting some variables but have been unable to achieve the desirable outcome.

If someone could point me in the right direction of what to do, it would be most appreciated.

Thank you!

Tre

  • 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-05T16:47:27+00:00Added an answer on June 5, 2026 at 4:47 pm

    Basically you have to remember $the_time from every row at the end of your loop, and compare it to the current $the_time to decide if you have to echo a new <dt>. The fact that each day has its own <dl> complicates things a bit, though. Here is an ugly solution:

    // Init empty previous time
    $previous_time = null;
    // Open first definition list
    echo '<dl class="calendar-day first-child">';
    foreach($results as $event) {
    
        $event_id = $event->id;
        $event_name = $event->event_name;
        $start_date = $event->start_date;
        $start_time = strtotime($event->start_time);
        $the_time = $start_time;
        $the_day = date('d', $start_time);
        $the_month = date('M', $start_time);
        $start_time = date('g:ia', $start_time);
    
        // Date changed
        if($the_time != previous_time) {
            // Unless first iteration, close previous list
            if(!empty($previous_time)) {
                echo '</dl>';
            }
            // Open new list
            echo '<dl class="calendar-day first-child">'
            // Show definition term for the group of events
            echo '<dt>';
            echo '<p class="the-month">' . $the_month . '</p>';
            echo '<p class="the-day">' . $the_day . '</p>';
            echo '</dt>';
        }
    
        // Display current event
        echo '<dd>';
        echo '<h4><a href="' . $event_id . '">' . $event_name . '</a></h4>';
        echo '<h5><span class="time">' . $start_time . '</span></h5>';
        echo '</dd>';
    
        // Remember date from previous row
        previous_time = $the_time;
    }
    // Close last definition list
    echo '</dl>';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to render a haml file in a javascript response like so:
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a view passing on information from a database: def serve_article(request, id): served_article
I'm making a simple page using Google Maps API 3. My first. One marker
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am using jsonparser to parse data and images obtained from json response. When

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.