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

  • Home
  • SEARCH
  • 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 3627058
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:50:25+00:00 2026-05-18T23:50:25+00:00

I need help, badly. What I am making right now is a date picker.

  • 0

I need help, badly. What I am making right now is a date picker. Pretty much updating on it for my own use.

I needed to block out specific date ranges. I found a code to do this, and it utilizes arrays. I like that.

What I then needed was a way to create the array with every date within the range, because I only entered the Start Date and the End Date. Found one. Works like a charm.

But now, I have a problem. It creates a new array using the same $. So the only array that the calender registers is the newest one. Essentially, what I need is just 1 array.

I’ve tried a few things, but nothing seems to work. Been thinking about this for a while now. Any help?

function createDateRangeArray($strDateFrom,$strDateTo) //Changes a Range of Dates to Specific Dates
    {
    $aryRange = array(); //Creates an Array

    $iDateFrom = mktime(1,0,0,substr($strDateFrom,5,2),     substr($strDateFrom,8,2),substr($strDateFrom,0,4));
    $iDateTo = mktime(1,0,0,substr($strDateTo,5,2),     substr($strDateTo,8,2),substr($strDateTo,0,4));

    if ($iDateTo >= $iDateFrom)
        {
        array_push($aryRange,date('Y-m-d',$iDateFrom)); // first entry

        while ($iDateFrom<$iDateTo)
            {
          $iDateFrom += 86400; // add 24 hours
          array_push($aryRange,date('Y-m-d',$iDateFrom));
            }
        }

    return $aryRange; //Returns to step 1 and adds another value into the array
    }


$d = "SELECT startdate, enddate FROM classdetails";
$f = mysql_query($d);

while ($e = mysql_fetch_array($f)) 
    {
    while (list($g, $h) = each($e)) { $$g = $h; } 
        {
        $aryDates = createDateRangeArray($startdate,$enddate);
        print_r($aryDates);
        echo "<br />";
        }
    }


And for those wondering, I do include references of where some of my work is taken from, even if heavily modified.

As you can see, the problem lies with the fact that once it creates an array, it just creates a new one. I’ve tried using ifelse statements, empty(), isset(), increments (didn’t even know how to use them, just thought a long time and deleted it).

So, what can I do here?

What I always get back is (I only have 2 rows of dummy data):


Array ( [0] => 2010-12-16 [1] => 2010-12-17 [2] => 2010-12-18 [3] => 2010-12-19 [4] => 2010-12-20 [5] => 2010-12-21 [6] => 2010-12-22 [7] => 2010-12-23 )
Array ( [0] => 2010-12-25 [1] => 2010-12-26 [2] => 2010-12-27 [3] => 2010-12-28 [4] => 2010-12-29 )

The problem lies with the loop itself. The first instance does what it is tole to do. The second instance onwards, $aryDates just gets replaced.

Any help would be greatly appreciated.

  • 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-18T23:50:25+00:00Added an answer on May 18, 2026 at 11:50 pm
    while (list($g, $h) = each($e)) { $$g = $h; } 
    

    Oh good god. Do NOT use variable variables. Especially when you’ve got a perfectly good array being generated by the mysql fetch call as is. THis is why you’re having trouble debugging your code.

    You could rewrite the while loop like this

    while ($e = mysql_fetch_array($f)) {
        $aryDates = createDateRangeArray($e['startdate'],$e['enddate']);
        print_r($aryDates);
        echo "<br />";
    }
    

    Far more readable, far easier to follow what’s happening, and absolutely NO NEED WHATSOEVER for variable variables.

    You penance is 500 lashes with a wet noodle while repeating the following mantra: “I shall not use variable variables”

    Beyond that, of course it’s creating a new array each time, you’re telling it to at the top of your createDateRange function:

    $aryRange = array(); //Creates an Array
    

    If you want to reuse the same array over multiple function calls, make it a static variable:

    static $aryRange = array();
    

    which will preserve it across successive calls, which would then let you append each calls’s dates.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help very badly. I'm working on a project where a bulk
Hi Java programmers. I badly need your help. I have a JavaFX/Java ME application.
Need help in figuring out a way to fetch a particular block of content
Need help writing a regular expression to match any class containing the phrase block-container
I need help on this following aspx code aspx Code: <asp:Label ID =lblName runat
I need help understanding some C++ operator overload statements. The class is declared like
I need help with this route map routes.MapRoute(Blog_Archive, Blog/Archive/{year}/{month}/{day}, new { controller = Blog,
I need help getting my head around the difference between my current OOP notion
I need help with the best practice to localize asp mvc apps, I saw
I need help to replace all \n (new line) caracters for in a String,

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.