[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 08-27-2008, 04:50 AM   #1 (permalink)
DomainersUniversity.com

Team Leader

 
Gene's Avatar
 
Join Date: Feb 2005
Location: Oswego, NY
Posts: 4,718
96.11 NP$ (Donate)

Gene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond repute

Ethan Allen Fund Cancer Survivorship Baby Health Cystic Fibrosis Marrow Donor Program Parkinson's Disease Child Abuse
Need a special PHP 'include'

Let's say I have hundreds of HTML files, each named for a particular day of the year.

I need to use the PHP 'include' code so on any particular system date, the matching HTML file is included. So, since today is August 27, 2008, the 'include' file should be 2008-08-27.html

Understand that the html files have not been created yet, so the naming of these files can be in a different date format if need be.

------------------------

Then I need to have another 'include' code that will take the system date and subtract a number of days, so it will 'include' a HTML file that is X number of days in the past.

For example, today is August 27, 2008, and I want the web page to 'include' a file named for a date 3 days ago, which would be 2008-08-24.html.

------------------------

Seems like a fairly simple thing to do, but I don't know coding well enough to figure it out. Any help would be great!




.
__________________
.
.

Gene is offline  
Old 08-27-2008, 05:15 AM   #2 (permalink)
No Country for Old Domainers ...

Member Services

 
Mark's Avatar
 
Join Date: Mar 2004
Posts: 9,873
4,750.95 NP$ (Donate)

Mark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond repute

Ethan Allen Fund
Well the part of it to include "Today" could be :

Code:
<?php

$today = date("Ymd");

include("includes/$today.php");

?>
That would actually show the date as "20080827" - And as a whole number you could simply Subtract numbers from that to show archives of days past.

Code:
$yesterday = $today-1;

That may be a bit too simple for what you are looking for Gene - But it's 8 AM here and I'm out of Mountain Dew

SOS DEW ME !

Obviously - That is limited to one month though ...
Mark is offline  
Old 08-27-2008, 05:44 AM   #3 (permalink)
DomainersUniversity.com

Team Leader

 
Gene's Avatar
 
Join Date: Feb 2005
Location: Oswego, NY
Posts: 4,718
96.11 NP$ (Donate)

Gene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond repute

Ethan Allen Fund Cancer Survivorship Baby Health Cystic Fibrosis Marrow Donor Program Parkinson's Disease Child Abuse
Thanks Mark!
That seems like it would work (based on my limited understanding of PHP), but I'm wondering why you say it would be limited to 1 month. Couldn't it say $yesterday = $today-47; for instance?


So do I have this right?

PHP Code:
<?php

$today
= date("Ymd");
$yesterday = $today-1;
include(
"includes/$today.php");

?>

(which would use file: 20080827.php)



OR



<?php

$today
= date("Ymd");
$yesterday = $today-3;
include(
"includes/$yesterday.php");

?>

(which would use file: 20080824.php)

----------------------------
EDIT: Mark, you're da man! I just tried the code and it works perfectly. THANK YOU!





.
__________________
.
.


Last edited by Gene; 08-27-2008 at 06:24 AM.
Gene is offline  
Old 08-27-2008, 06:46 AM   #4 (permalink)
No Country for Old Domainers ...

Member Services

 
Mark's Avatar
 
Join Date: Mar 2004
Posts: 9,873
4,750.95 NP$ (Donate)

Mark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond repute

Ethan Allen Fund
No - it wont work for other months due to the fact it is combining Y M D into one number. "20080827" is just "20 Million 80 thousand and 27" to the script. If you subtract more than 26 , There would be an error if you tried to incude any pages.

For individual dates , You really need a more detailed Calendar set up and something in the script to ask "if file exists" to make sure it doesn't try to include dates non-existent. http://www.php.net/date has all of the available formats. I'm thinking in your case maybe using the "Day of Year" format may help.
Quote:
z The day of the year (starting from 0) 0 through 365
Here is a piece of a script I use to pull up "Todays Database" :

Code:
$today = date("Ymd");
if(!isset($filename) || !$filename || $filename == ""){$filename = "database/$today.txt";}
	if(!file_exists("$filename")) {

///it does exist - so retrieve and show data (include it in your case)

} else {

///it doesn't exist - So no Go (I actually create the database here on my script)

}
I'll do some more thinking and digging on it after a Trip to the store (Mountain Dew Trip)

I'd bet some of these younger "whippersnappers" might have a better way to do this than me
Mark is offline  
Old 08-27-2008, 06:58 AM   #5 (permalink)
DomainersUniversity.com

Team Leader

 
Gene's Avatar
 
Join Date: Feb 2005
Location: Oswego, NY
Posts: 4,718
96.11 NP$ (Donate)

Gene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond repute

Ethan Allen Fund Cancer Survivorship Baby Health Cystic Fibrosis Marrow Donor Program Parkinson's Disease Child Abuse
You're right... I just tried doing a -30 and it failed... it won't overlap into the previous month. Thanks for the additional info though!
__________________
.
.

Gene is offline  
Old 08-27-2008, 06:58 AM   #6 (permalink)
Traveller
 
-NC-'s Avatar
 
Join Date: Mar 2007
Location: Yet another city
Posts: 1,392
614.57 NP$ (Donate)

-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of

Animal Cruelty Animal Rescue Ethan Allen Fund Protect Our Planet
The strtotime function is almost unbelievably clever at working out date stuff, you can even tell it what to do in almost plain english:

Code:
$yesterday = date('Ymd', strtotime("-1 day"));
$lastmonth = date('Ymd', strtotime("-1 month"));
check out some of the more extreme examples:
Code:
strtotime("last Monday")
strtotime("next Thursday")
http://php.net/strtotime
-NC- is offline  
Old 08-27-2008, 07:07 AM   #7 (permalink)
DomainersUniversity.com

Team Leader

 
Gene's Avatar
 
Join Date: Feb 2005
Location: Oswego, NY
Posts: 4,718
96.11 NP$ (Donate)

Gene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond repute

Ethan Allen Fund Cancer Survivorship Baby Health Cystic Fibrosis Marrow Donor Program Parkinson's Disease Child Abuse
-NC-! Beautiful! That works like a charm... man you've saved me a lot of hair-pulling. Thanks so much.
__________________
.
.

Gene is offline  
Old 08-27-2008, 09:53 AM   #8 (permalink)
No Country for Old Domainers ...

Member Services

 
Mark's Avatar
 
Join Date: Mar 2004
Posts: 9,873
4,750.95 NP$ (Donate)

Mark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond reputeMark has a reputation beyond repute

Ethan Allen Fund
I told you one of those Younger folks would know a better way

Thanks -NC-
Mark is offline  
Old 08-27-2008, 09:59 AM   #9 (permalink)
DomainersUniversity.com

Team Leader

 
Gene's Avatar
 
Join Date: Feb 2005
Location: Oswego, NY
Posts: 4,718
96.11 NP$ (Donate)

Gene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond repute

Ethan Allen Fund Cancer Survivorship Baby Health Cystic Fibrosis Marrow Donor Program Parkinson's Disease Child Abuse
Thanks to both of you for taking the time! And Mark, you're still the best eye-poker
__________________
.
.

Gene is offline  
Old 08-28-2008, 05:36 PM   #10 (permalink)
Senior Member
 
Join Date: Apr 2005
Location: Joliet, Illinois
Posts: 1,194
345.00 NP$ (Donate)

RageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to behold

Child Abuse
Good call, glad I read this thing through instead of just posting like normal then I would've made a double post xD good job -NC-

-RageD
RageD is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 03:23 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85