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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:00:34+00:00 2026-06-12T20:00:34+00:00

I feel like I may be over-thinking this solution… so I figured I’d get

  • 0

I feel like I may be over-thinking this solution… so I figured I’d get some additional advice. I want to query my database for a list of ‘events’ and group events that have the same date under a single header in addition, I want this ‘group’ in it’s own container. I’ve figured out the single header issue browsing other questions, but the container is giving me grief!

For Example:

This:

<div class='container'>
    <img src='event-image.jpg'>
    <h1>October 15th, 2012</h1>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <img src='event-image.jpg'>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
    <h3>Event Name</h3>
    <p>Details</p>
</div>

Not This:

<div class='container'>
    <img src='event-image.jpg'>
    <h1>October 15th, 2012</h1>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <img src='event-image.jpg'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>
<div class='container'>
    <h3>Event Name</h3>
    <p>Details</p>
</div>

This:

October 15, 2012
Event 1
Event 2
Event 3

Not This:

October 15, 2012
Event 1
October 15, 2012
Event 2
October 15, 2012
Event 3

MySQL Query:

$sql = "SELECT title, DATE_FORMAT(date, '%M %D, %Y') AS postdate, time, venue, cost, city,   spotlight, image
        FROM shows WHERE date >= $curDate
        ORDER BY date ASC, spotlight DESC LIMIT $startRow," . SHOWMAX;

HTML/PHP:

<?php 
    $prevDate = null;
    while ($row = $result->fetch_assoc()) { ?>
        <div class="content">
        <?php 
        if (!empty($row['image'])) { ?>
            <img src="/images/thumbs/<?php echo $row['image'] ?>">
        <?php 
        }

        if ($row['postdate'] != $prevDate) { ?>
            <h1><?php echo $row['postdate']; ?></h1>
            <?php $prevDate = $row['postdate'];
        } ?>
        <h3><?php echo $row['title']; ?></h3>   
        <p><?php echo $row['venue'] . " | " . $row['city'] . " | " . $row['time'] . " | " .  $row['cost']; ?></p>
        </div>
    <div class="horizontal-line"></div>
<?php } ?>

Results:

<div class="content">
<img src="/images/thumbs/defining-times-news-00.jpg">
    <h1>October 13th, 2012</h1>
    <h3>Relient K w/ Hellogoodby, William Beckett & House of Heroes</h3>    
    <p>Cain's Ballroom | Tulsa, OK | 9:00 | $10</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <h3>Rod Steward & Stevie Nicks</h3> 
    <p>BOK Center | Tulsa, OK | 9:00 | $45</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <h3>Gary Allan</h3> 
    <p>Hard Rock Hotel & Casino | Tulsa, OK | 9:00 | $30</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <img src="/images/thumbs/dead-sea-choir-news-00.jpg">
    <h1>October 14th, 2012</h1>
    <h3>Nalani Proctor and Kierston White</h3>  
    <p>Bluebonnet | Norman, OK | 9:00 | $5</p>
</div>
<div class="horizontal-line"></div>
<div class="content">
    <h3>Bungalouski</h3>    
    <p>Bluebonnet | Norman, OK | 9:00 | FREE</p>
</div>
<div class="horizontal-line"></div>
    <h3>Relient K w/ Hellogoodby, William Beckett & House of Heroes</h3>    
    <p>Cain's Ballroom | Tulsa, OK | 9:00 | $10</p>
</div>
<div class="horizontal-line"></div>

I hope this isn’t too convoluted! Any help is appreciated! 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-12T20:00:35+00:00Added an answer on June 12, 2026 at 8:00 pm

    Try this:

    $prevDate = null;
    while ($row = $result->fetch_assoc()) {
        $mark = false;
        if ($row['postdate'] != $prevDate) {
            $mark = true;
            $prevDate = $row['postdate'];
        }
        ?>
        <? if ($mark) { ?>
            <div class="content">
            <? } ?>
            <? if (!empty($row['image'])) { ?>
                <img src="/images/thumbs/<?= $row['image'] ?>">
            <? } ?>
    
            <? if ($mark) { ?>
                <h1><?= $row['postdate']; ?></h1>
            <? } ?>
            <h3><?= $row['title']; ?></h3>   
            <p><?= $row['venue'] . " | " . $row['city'] . " | " . $row['time'] . " | " . $row['cost']; ?></p>
            <? if ($mark) { ?>
            </div>
            <div class="horizontal-line"></div>
        <? } ?>
    <? } ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I feel like such a noob asking this but, for some reason a horizontal
This may be a very stupid question and it's making feel like my brain
I feel like I am not writing this correctly and this is my first
I feel like I've only ever seen this here on SO, but I can't
I feel like there's a pretty simple way to do this, but I'm not
I feel like this is something I should already know, but I'm just not
I know this may not be exactly a coder question, but I feel it
I've been learning C# over the summer and now feel like making a small
I feel like I may be overlooking a fundamental concept of the page life-cycle
This may be a question for Server Exchange but I am starting to feel

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.