Jump to content

Pulling sunset time from txt file and displaying on site daily


master4g

Recommended Posts

Hey everyone. Currently I have a site set up where I manually edit the txt file and the site pulls it from the text file and displays via php. I wanted to automate it by creating one file which contains the sunset times for the whole year, and have php determine todays date and then display the corresponding sunset time.

 

Can someone please point me in the right direction?

 

maybe it can be set up in a way where each line in the txt file represents the day of the year. ex: Jan 1 would be line 0, Feb 1's sunset time would be on line 31 etc.

 

Thanks

Link to comment
Share on other sites

Thanks for all the replies. I am relatively new to PHP so some of those suggestions flew past my head.

 

I currently have a paper with the desired times for each day of the year, which I can sit down and input into the computer depending on how I decide to store the info.

 

I don't have experience with databases but If I was pointed in the right direction, I can research and try to figure it out.

 

xyph: can you please elaborate on using an INI to store? do you have any link or tip I can follow to look into that. Thanks

 

Also, I can use the php sunset feature, but I would like to learn another way (like the txt file with the data, or an INI? or database) because hopefully in the future I can use this coding for another similar project which goes as follows: example: show a certain time for a certain date frame so from Jan1-Jan19 show "6:30" and then from Jan20-Feb23 show "6:45" , etc.

Link to comment
Share on other sites

@master4g:

 

Look at Pikachu2000's response. There are built-in functions in PHP (I didn't realize this) that will return the sunrise, sunset, etc. information AUTOMATICALLY. You do not need to do anything - no data entry. PHP is all knowing! Well, not really, but it is simply a mathematical calculation for the sunrise/sunset for any given latitude/longitude.

 

Look at the functions he linked to

Link to comment
Share on other sites

To actual answer your more direct question:

 

This is a very basic PHP/SQL question.  Create a table in MySQL with 4 columns:

Start, End, Sunrise, Sunset

 

Start and End should be of DATETIME format.  When you input your data, make sure the records always butt up against each other and do not overlap:

2011-09-11 00:00:00, 2011-09-13 23:59:59, 6:45, 7:12

2011-09-14 00:00:00, 2011-09-17 23:59:59, 6:53, 7:22

 

Have an HTML form with a date picker or an input box (for testing, you want date formats like YYYY-MM-DD).

 

The PHP script that queries the database should accept the inputted date, format it to YYYY-MM-DD format (if necessary), and perform the query:

SELECT Sunrise, Sunset FROM thatTableYouMade WHERE '{$theInput}' BETWEEN Start AND End;

 

The result, which should be one row, will have the sunrise and sunset time.

 

-Dan

Link to comment
Share on other sites

mjdamato, as much as I hate to turn your posts back at you, but did you look at what he said?  he doesn't want to use the sunrise and sunset functions because this is a thought experiment about displaying any data for a specific date based on date ranges stored in a table. 

 

master4g, given the table structure I gave you earlier, a query for "sunrise and sunset today" would be:

 

SELECT Sunrise, Sunset FROM thatTableYouMade WHERE NOW() BETWEEN Start AND End;

 

-Dan

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.