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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:13:04+00:00 2026-05-19T13:13:04+00:00

I’ve tried to make this work for 24 hours now, and now it feels

  • 0

I’ve tried to make this work for 24 hours now, and now it feels like I’m close to it!

I would like to get date (column:datum) and location (column:plats) from MySQL, where my code looks like:

<?php

$sql = "SELECT datum FROM gigs GROUP BY DATE_FORMAT( datum, '%Y' ) ORDER BY datum DESC";
$result = mysql_query($sql);

 while($r = mysql_fetch_array($result)) {

  $date = $r['datum'];
  $date_new = new DateTime($date);
  $year = $date_new->format('Y');
  $month = $date_new->format('M');
  $day = $date_new->format('d');

  $sql2 = "SELECT * FROM gigs WHERE DATE_FORMAT( datum, '%Y' ) = $year ORDER BY datum ASC";
  $result2 = mysql_query($sql2);

  echo "<tr height=20px><td></td><td align=center><b>".$year."</b></td></tr>";

  echo "<tr><td><b>".$month."</b></td></tr>";

  while($r2 = mysql_fetch_array($result2)) {

   $date2 = $r2['datum'];
   $date_new2 = new DateTime($date2);
   $year2 = $date_new2->format('Y');
   $month2 = $date_new2->format('M');
   $day2 = $date_new2->format('j');

 //echo "<b>Month: ".$month."</b>";
 //echo "<b>Month2: ".$month2."</b>";

    if($month != $month2) {
     echo "<tr><td>&nbsp;</td></tr><tr><td><b>".$month2."</b></td></tr>";
    }

    $month = $month2;

    echo "<tr class=giglist><td>".$day2."</td><td>".$r2['plats']."</td></tr>"; 



  }
    echo "</td></tr>";
 }

?>

This gives me:

2011
Jan
1. Location
2. Location
3. Location
...

Feb
1. Location
2. Location
3. Location
...
...
Dec
1. Location
2. Location
3. Location
...

2010
Dec

Jan
1. Location
2. Location
3. Location
...
Feb
1. Location
2. Location
3. Location
...
...
Dec
1. Location
2. Location
3. Location
...

I do NOT want the extra December written under “2010”…

I hope someone can help, cause I’m lost in my own code xD 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-05-19T13:13:05+00:00Added an answer on May 19, 2026 at 1:13 pm

    Your code is to much complicated, you can do that with only one query, see this code

    <?php 
    $sql = 'SELECT
                *, 
                DATE_FORMAT( datum, "%Y" ) "year", 
                DATE_FORMAT( datum, "%M" ) "month", 
                DATE_FORMAT( datum, "%e" ) "day" 
            FROM gigs
            ORDER BY year DESC, month DESC, day ASC';
    
    $year = null;
    $month = null;
    $stmt = mysql_query($sql);
    while($row = mysql_fetch_array($result)) {
        if ($year != $result['year']) {
            // Year changed
            $year = $result['year'];
            echo "<tr height=20px><td></td><td align=center><b>".$year."</b></td></tr>";
        }
        if ($month != $result['month']) {
            // Month changed
            $month = $result['month'];
            echo "<tr><td>&nbsp;</td></tr><tr><td><b>".$month."</b></td></tr>";
        }
        echo "<tr class=giglist><td>".$result['day']."</td><td>".$row['plats']."</td></tr>"; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.