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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:13:32+00:00 2026-06-14T19:13:32+00:00

I know this one is strange. I have a table called schedule with a

  • 0

I know this one is strange. I have a table called schedule with a column called Date with the column type being DATE. I have dates (in YYYY-MM-DD format) from 2012-11-01 to 2013-01-02 in this column. What’s happening is if I enter a date, any date, that has 2012-12-01 anywhere in between, it restarts the loop. So if I select 2012-11-15 to 2012-12-15 it will print from Novemeber 15th to December 1st, but then after December 1st it starts printing again at November 15th. If I select 2012-11-15 to 2012-11-30 or 2012-12-02 to 2012-12-30 everything works fine, it’s just when that particular date is involved that it causes problems. Here is my code:

<?php
////////////////////////////////////////////////////////
//////First set the date range that we want to use//////
////////////////////////////////////////////////////////

if(isset($_POST['from']) && ($_POST['from'] != NULL))
    {
    $startDate = $_POST['from'];
    echo "<script>alert (\"startDate: " . $startDate . "\")</script>";
    }
else
    {
    //Default date is Today
    $startDate = date("Y-m-d");
    echo "<script>alert (\"startDate: " . $startDate . "\")</script>";
    }
if(isset($_POST['to']) && ($_POST['to'] != NULL))
    {
    $endDate = $_POST['to'];
    echo "<script>alert (\"endDate: " . $endDate . "\")</script>";
    }
else
    {
    //Default day is one month from today
    $endDate = date("Y-m-d", strtotime("+1 month"));
    echo "<script>alert (\"endDate: " . $endDate . "\")</script>";
    }

//////////////////////////////////////////////////////////////////////////////////////
//////Next calculate the total amount of days selected above to use as a limiter//////
//////////////////////////////////////////////////////////////////////////////////////

    $dayStart = strtotime($startDate);
    $dayEnd = strtotime($endDate);
    $total_days = abs($dayEnd - $dayStart) / 86400 +1;
    echo "<script>alert (\"Total Days: " . $total_days . "\")</script>";

//////////////////////////////////////////////////////////////////////////////////////////////////////////
//////Then we're going to get the date range specified from the schedule table and print the results//////
//////////////////////////////////////////////////////////////////////////////////////////////////////////

//Select the dates from the schedule table, limited to the total amount days.
$sql = ("SELECT Date FROM schedule WHERE Date BETWEEN '$startDate' AND '$endDate' LIMIT $total_days");

//Run a check on the query to make sure it worked. If it failed then print the error.
if(!$result_date_query = $mysqli->query($sql))
    {
    die('There was an error getting the date from the schedule table [' . $mysqli->error . ']');
    }

//Loop through the results while a result is being returned.
while($row = $result_date_query->fetch_assoc())
    {
    //First format and then print the all the dates selected.
    echo "<td class=\"schedule_date_cell\">" . date('M j', strtotime($row['Date'])) . "</td>";
    }

//Free the result.
$result_date_query->free();
?>

I am at a loss. I’ve added in some echo statements to show what’s going on and everything is as expected. I just don’t understand how all dates before and all dates after work perfectly, but anything that has Dec 1st in it makes it restart the loop. I’m not sure if it’s relevant, but there are multiples of the same dates in the column, which is why I have set LIMIT in the query.

I’m hoping someone can crack this case wide open as I’m dying to know the answer!

**EDIT: **I tried this same query from within PHPmyadmin as suggested in the comments, and it produces the same results. I also tried removing the LIMIT as well as changing from single quotes '2012-11-01' to double quotes "2012-11-01" with still the same results.

**EDIT2: **For each date in the Date column, there are 92 instances of each date. So, for example, there are 92 records of 2012-12-01 and 92 records of 2012-12-02 and so on. The interesting thing is, when I remove LIMIT from the query and use the date range of 2012-11-30 to 2012-12-15 (Nov 30th to Dec 15th) is prints Nov 29th, Nov 30th, Dec 1st then repeats those three dates again and again, 92 times! Then after that it starts to print the rest of the days Dec 2nd, Dec 3rd, Dec 4th …Dec 15th and then repeats THOSE dates again and again, 92 times! This just proves that for some reason the loop is restarting at Dec 1st because if I enter a date range of Nov 1st to Nov 3rd it prints all dates in the range before repeating itself 92 times. The reason for the LIMIT was so to stop it from returning all instances of each date, so I would only get Nov 1st to Nov 3rd one time and not 92 times, but when the limit is removed we can see that Dec 1st is causing some weird issues.

**EDIT3: **I created a new table schedule2 identical to schedule and entered the same date range of 2012-11-01 to 2013-01-02, but this time with only one instance of each. Then I ran my query again and it works perfectly, in any date combination. So obviously the problem is that there is more than one instance of this date in the schedule table, but I can’t figure out WHY it’s a problem. I don’t understand what this date is having an affect on the while loop. And before you suggest it, yes, I do need to have multiple instances of the same date in the table 😉

  • 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-14T19:13:33+00:00Added an answer on June 14, 2026 at 7:13 pm

    The fact that it loops at Dec 1st is for the most part just a coincidence. I don’t know the specifics of how MySQL works internally, but if you don’t give it an order, then it will apply whatever order it feels like to the data when you request it.

    Combine this with the fact that you have duplicate dates, and then you end up with the situation have you described spontaneously happening for no apparent reason.

    Since you want each date exactly once, and you want them to appear in order chronologically, then you need to tell MySQL you want those two things when you make the query. As such, add DISTINCT AND ORDER BY commands:

    SELECT DISTINCT(Date) FROM schedule WHERE Date BETWEEN '$startDate' AND '$endDate' ORDER BY Date ASC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this one is the weirdest of all weird questions I have asked
I know this is largely an opinion, but I'm interested if you have one
I know this is bit of a strange one but if anyone had any
Strange one here, dealloc is not being called when dismissed from inside a block.
I have a query that joins two tables. One table has a column that
Ok, so this one is a bit strange.... I have an HTML page in
I know this one has been asked few times already ( 1 , 2
This is one of those I probably should know this, but I don't questions.
This one goes round and round I know but I can't seem to find
I know there are questions similar to this one, but I've not found a

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.