sha v. 3.1run, sha sha, runsign my guestbook!
mainabout meschool/resumephotosguestbooklinks
donate

current

Run, Sha Sha, Run

As of 10/30/08, 11:21pm:

Reading:

Dean Karnazes
Ultramarathon Man: Confessions of an All-Night Runner

Full list...

Playing:

Mass Effect

Super Mario Galaxy

Phoenix Wright Ace Attorney: Trials and Tribulations
Listening To:

Jem
Down to Earth


Watching:

Veronica Mars - The Complete Third Season

The Bourne Ultimatum

Young@Heart

Dexter - The Complete Second Season

Once

Weeds - Season Two

Dixie Chicks: Shut Up & Sing

Autism - The Musical

Red Without Blue


features
Pooh's Big Airplane Adventure

Shannen Doherty: A Study in Asymmetry

Indian Sonny and Cher Look-a-likes


etc
bunny!
moveable type 2.5
You are logged out. Click here to login.

« Much Food | Main | Burnout »

September 16, 2004


MOVEABLE AWESOME

WARNING: This will be a nerdy entry. Yes, even more so that usual. There, I said it.

So...I'm okay at web-y stuff. I don't think I'm the bestest ever, but sometimes I do stuff that I think is kinda cool. Today I did one of those things, and I'd like to share it with you.

You may or may not have noticed that I created a marathon log recently. It's been live for a few days, but I'm still in the process of hammering out the details. One of those details was that, for each day I had an entry on, I wanted to keep track of which day of training it was, how much money I had raised, and how many days I have left to fundraise. At first, I was typing them in manually into each entry. This quickly became tedious, so I started looking into a more automated way of doing this.

While reading about PHP time functions, (hey, I said this would be nerdy) I happened upon this comment which gave a code snippet to calculate the elapsed days between two dates. This was perfect for what I was trying to do. So I created couple new templates which have something like this:

$firstdayoftraining = "18 September 2004";
$fundraisingdeadline = "26 November 2004";

$dayselapsed = round((strtotime($today) - strtotime($firstdayoftraining))/(60*60*24));
if($today >= $firstdayoftraining) {
$dayselapsed = $dayselapsed + 1;
}
$dayselapsed2 = round((strtotime($fundraisingdeadline) - strtotime($today))/(60*60*24));
$s = " ";
if($dayselapsed2 != 1) {
$s = "s ";
}

echo "Day " . $dayselapsed . " of training";
echo $dayselapsed2 . " day" . $s . "left to fundraise";

I include them in my Movable Type templates right after the date. I also have to add this before the includes:

$today = <$MTEntryDate format="%d %B %Y">;

This way, the elapsed days are calculated automatically from the date of each entry.

The last thing I needed to do was some way of keeping track of how much money I had raised so far in each entry. It wasn't as simple as including one file because the total would (presumably) be different for different entries. I wanted to able to look back and see my progress. I thought about this for a bit and came up with what I think is a pretty clever solution. For each entry, I put the current fundraising total in the "Extended Entry" field. Next, I created a new daily archive template that only had the following:

<MTEntries lastn="1"><$MTEntryMore$></MTEntries>

I set the archive file name to be: fundraising/<$MTArchiveDate format="%Y_%m_%d"$>.php. So for each day that has an entry, a file is created in the fundraising/ folder.

So for each day, I include that day's fundraising total in the template:

include '[path]/archives/fundraising/<$MTEntryDate format="%Y_%m_%d"$>.php';

The last thing I did was to leverage those new fundraising total files for donation box on the left side. I added the following code:

Total:
<MTEntries sort_order="descend" lastn="1">
<?php include '[path]/archives/fundraising/<$MTEntryDate format="%Y_%m_%d"$>.php'; ?>

Assuming the fundraising total for the last entry is the current total, the donation box on the left side will automatically update as I create new entries.

So...all that was probably only interesting to me, but I was quite proud of myself. And now my site is quite easy to maintain. Woo!

[12:13 AM]

+++++

Post a Comment
(*) Required fields

* Name:


* Email Address: (Required, but will not be displayed)


URL:



* Please retype the above number:


* Comments:


Remember info?



S M T W T F S
      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    

recent entries
- Things Are Lookin' Up
- Parking garage
- Sunset sky
- Waiting for the vet
- Half Enzo
- Wistful Enzo
- Dusk sky
- Why I Love Nachos
- This is Sparta!
- Sutro fishermen


full archives
March 2007
February 2007
January 2007
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
January 2004
December 2003
November 2003
October 2003
September 2003
August 2003
July 2003
June 2003
May 2003
April 2003
March 2003
February 2003
January 2003
December 2002
November 2002
October 2002
September 2002
August 2002
July 2002
June 2002
May 2002
March 2002
February 2002
January 2002
December 2001
October 2001
September 2001
June 2001
May 2001
March 2001
February 2001


search the posts



  ©2003 Sha Sha Chu e-mail me  
recent photos

www.flickr.com
This is a Flickr badge showing public photos from Sha Sha Chu. Make your own badge here.