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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:50:28+00:00 2026-06-01T21:50:28+00:00

What I’m trying to do is grab entries from an updates table in a

  • 0

What I’m trying to do is grab entries from an updates table in a mysql database using php. Each entry has a timestamp attached to it. First, I grab 10 distinct dates from the timestamp, create a new array using those 10 unique dates (I do this because the fetchAll put the dates into a multidimensional array), then do another database call grabbing all entries that has those dates. Which can return more than 10 entries. I want it to have 10 distinct dates, not 10 distinct timestamps.

For example, if 2012-03-25 showed up in the first call from distinct dates, it can find:

2012-03-25 00:58:53
2012-03-25 00:58:02
2012-03-25 00:57:20
2012-03-25 00:56:35
2012-03-25 00:55:58
2012-03-25 00:53:20
2012-03-25 00:52:32
2012-03-25 00:51:45

Since the timestamps are different.

Here is the current code I am using, which works.

$test = $dbh->getArray("SELECT DISTINCT DATE_FORMAT(added, '%Y-%m-%d') AS added FROM db_updates ORDER BY added DESC LIMIT 0,10");

foreach ($test as $entry) {
  list($date) = $entry;
  $output[] = '\''.$date.'\'';
}  

$test2 = $dbh->getArray("SELECT * FROM db_updates WHERE DATE_FORMAT(added, '%Y-%m-%d') IN (".implode(',', $output).") ORDER BY added DESC");

print_r($test2);

This returned 33 results.

Just in case anyone ask, I am using PDO and not the mysql function in php. That code is here:

public function getArray($query) {
  $result = $this->db->query("$query");
  return $result->fetchAll(PDO::FETCH_NUM);
}

This all works 100%, and it does what I want it to do. However, my question is if there is a way to do all this with just a single mysql call, so I don’t have to call twice with a loop in the middle.

I tried to figure it out myself by searching google, and trial and error using joins and such to no avail.

  • 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-01T21:50:30+00:00Added an answer on June 1, 2026 at 9:50 pm

    It should work with an INNER JOIN, and you can just use DATE(added) instead of DATE_FORMAT() to strip off the time portion of the DATETIME values:

    SELECT * 
    FROM
      db_updates
      INNER JOIN (
        /* Subquery returns most recent 10 dates */
        SELECT DISTINCT DATE(added) AS added FROM db_updates ORDER BY added DESC LIMIT 0,10
      /* JOIN between dates */
      ) datelist ON DATE(db_updates.added) = datelist.added
    ORDER BY db_updates.added DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.