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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:55:50+00:00 2026-06-17T11:55:50+00:00

I’m attempting to make a this day in history type of page using PHP

  • 0

I’m attempting to make a “this day in history” type of page using PHP and mySQL. In the mySQL database, I have the following columns for each entry: id, date, topic, event. The date column uses the mySQL date type which is YYYY-MM-DD. I’m trying to use the date function in PHP to call the corresponding mySQL entry with the same date, but I can’t figure out how to connect them.

This first section successfully returns everything from the database.

<?php

$config ['db'] = array (
'host'      =>  'localhost',
'username'  =>  'root',
'password'  =>  'root',
'dbname'    =>  'party'
);

$db = new PDO('mysql:host=' . $config['db']['host'] . ';dbname=' . $config['db']['dbname'] , $config['db']['username'] , $config['db']['password']);

$query = $db->query("SELECT `events`.`date`, `topic`, `event` FROM `events`");

$rows = $query->fetchAll(PDO::FETCH_ASSOC);

echo '<pre>', print_r($rows, true), '</pre>';

However, I don’t want to display everything, just the row that contains the same month and day as the current date. How would I properly loop through and display only the single row? Here is where I ended.

//current day and month
$current_date = date("m d");

//select from database of events where matching month and day     
$statement = $db->prepare("SELECT * FROM `events` WHERE `date` = :md ");

$statement->execute(array(':md' => $current_date));

//echo out events that happened throughout history
echo "On ", date('F jS'), ", the following events took place:";

while($rows = $statement->fetch()){

    echo $rows['topic'];
    echo $rows['event'];
}

The only thing it prints out is “On current date, the following events took place:” Also, while it’s not of upmost importance, my current date is printing out one day in the future.

Thanks 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-06-17T11:55:51+00:00Added an answer on June 17, 2026 at 11:55 am

    I`d prefer to use mysql functions to extract month, day etc.

    Query:

     SELECT * FROM events WHERE EXTRACT(MONTH FROM date) = MONTH(NOW())
     AND EXTRACT(DAY FROM date) = DAY(NOW())
    

    Try to check mysql time zone settings and php zone settings to figure out why time one hour ahead.

    • 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
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I have thousands of HTML files to process using Groovy/Java and I need to
I have a view passing on information from a database: def serve_article(request, id): served_article

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.