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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:10:19+00:00 2026-05-22T16:10:19+00:00

Heres the problem… I have a loop looking like this selecting stuff from my

  • 0

Heres the problem…
I have a loop looking like this selecting stuff from my database.

$query = "SELECT * FROM table WHERE publish <= CURDATE() AND active = 'Yes' AND (YEAR(begin) = YEAR(CURDATE()) OR YEAR(begin) = YEAR(CURDATE()) + 1) ORDER BY begin ASC";
                        $resultSet = mysql_query($query);

                        if (mysql_num_rows($resultSet))
                        {
                        $newsArray = array();


                        while ($newsResult = mysql_fetch_array($resultSet))
                        {                                   
                        $newDate =  $newsResult['begin'] ;   
                        $timePeriod = date('F  Y ',strtotime($newDate));

                        $timePeriodY = date('Y',strtotime($timePeriod));
                        $timePeriodM = date('F',strtotime($timePeriod));                            

                        if (!isset($newsArray[$timePeriod]))
                        {
                        $newsArray[$timePeriod] = array();
                        }       
                        $newsArray[$timePeriod][] = $newsResult;                            
                        }                        


                        foreach ($newsArray as $timePeriod => $newsItems)
                        {  

                        $timePeriodY = date('Y',strtotime($timePeriod));

                        if ($timePeriodY == $thisYear){


                            }
                        else if ($timePeriodY == $nextYear){


                        }

                        echo '<h2 class="year>'.$timePeriodY.'</h2>';
                        echo '<ul class="column">';

                        foreach ($newsArray as $timePeriod => $newsItems)
                        { 
                        $timePeriodMonth = date('Y',strtotime($timePeriod));
                        if ($timePeriodY == $timePeriodMonth) {


                        $moSe = strftime('%B',strtotime($timePeriod));
                        $MonthSe = ucfirst($moSe);


                        $seMonth = str_replace($dateSearch,$dateReplace,date('F',strtotime($timePeriod)));

                        echo $seMonth;                     

                        foreach ($newsItems as $item)
                        {



                        $ad_event = date("Y-m-d",strtotime($item['event_end']));
                        $today = date("Y-m-d");




                            $dayMod = strftime('%e',strtotime($item['event_begin']));

                            $seDay = str_replace($dateSearch,$dateReplace,date('D',strtotime($item['event_begin'])));




                        echo '<a href="javascript:gotoDotBottom('.$item['event_id'].',\''.$item['event_url'].'\');" id="e'.$item['event_id'].'" class="eventLink '.$markedEvent.'" overhead="'.$item['event_title'].'" overdate="'.date("Y-m-d",strtotime($item['event_begin'])).'" overtext="'. strip_tags($showSum) .'">'.$seDay.' '.$dayMod.' - '.$item['event_title'].'</a>';
                        echo '</div>';
                        }  



                                    }            
                            }

                                                   }


                        }   

                        else
                            {
                        echo '';
                        }

This code outputs the data for each row and separates it for year month day etc. However some of the data is on the same day. Thats fine BUT when data is on the same day i want a variable that holds only the last of the items on that same day.

EX.

DB

PUBLISH      ID    NAME
2011-05-05   1     test 1
2011-05-05   2     test 2
2011-05-06   3     test 3

The result I would like from this is something like this

RESULT

test 1 ID 1 PUBLISH 2011-05-05 VARIABLE 2 <<-- see the variable that comes from test 2 row
test 2 ID 2 PUBLISH 2011-05-05 VARIABLE 2
test 3 ID 3 PUBLISH 2011-05-06 VARIABLE 3

Meaning test 1 in this case holds information about test 2 since test 2 is after test 1 and they both have the same date. If there is only one on the specific date as test 2 and 3 just echo the same id as the variable.

Any ideas? PLease tell me if i need to explain this even more 🙂

Thanks a lot for any help!

  • 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-22T16:10:20+00:00Added an answer on May 22, 2026 at 4:10 pm

    Group by date(begin)as you want only 1 record on the same date(begin) and since you want the latest order by dsc on column ‘begin’ (I believe the ‘begin’ is stored as datetime else you need to have dsc on table.ID)

    $query = "SELECT * 
                   FROM table 
                   WHERE publish <= CURDATE() 
                    AND active = 'Yes' 
                      AND (YEAR(begin) = YEAR(CURDATE()) 
                      OR YEAR(begin) = YEAR(CURDATE()) + 1) 
                     GROUP BY  begin
                     ORDER BY begin DSC";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my problem - I have some code like this: <mx:Canvas width=300 height=300> <mx:Button
Heres my problem. I have a mysql table called quotes. In one of the
heres the problem, i have a database thats hold information on marker images: i'm
Here's my problem - I'd like to communicate between two websites and I'm looking
Here's the problem: In C# I'm getting information from a legacy ACCESS database. .NET
Alright, so heres my problem: I have an application I am working with that
Heres my problem, I'm web developer and I have a web based script(PHP/CURL/HTML/JS) that
Ok heres my problem. I have a form that when it is not maximised,
I have very strange problem with Doxygen: I used it to create documentation from
i am trying to bulid this graph... heres the problem TAKE A LOOK AT

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.