we work magic with and CodeIgniter

Archive for November, 2009

Calculating age with PHP using a birth date

Posted on: November 15th, 2009 by Sam Hotchkiss

UPDATED 12/2: Code updated for efficiency and code download link added.

Ran into a problem today– there’s no easy way to add and subtract dates in PHP and be left with standard units (year, month, day, etc), so I whipped up a quick script to do it– the biggest problem is months, here, since PHP deals with second-based timestamps, and months don’t possess a standard number of seconds. Without further ado, here’s the code– I hope it’s helpful to your projects:
(more…)

An easy way to handle previous and next product links

Posted on: November 14th, 2009 by Sam Hotchkiss

I’m working on a custom eCommerce site for a customer right now, and ran into an issue– they wanted to have, on every product page, a forward and back button to get to the previous and next items. The problem with this is that they may have arrived on the product page in a couple of different ways, through search or browsing, with different criteria set.

I came up with this easy routine which goes through the result set, whether it’s search result or category view, then creates an array where the key is the current product ID, and the values are the IDs of the product before and the product afterward. So if I’m on product 157, $ordering[157]['next'] will give me the ID of the next product. Just pop it in a session, and you’re good to go.

Simple and straightforward– feel free to reuse all you like!
(more…)

Importing Basecamp Tasks into iCal

Posted on: November 6th, 2009 by Sam Hotchkiss

basecamp-logo-for-fluidI’ve been back and forth a thousand times on Basecamp– I love it and I hate it, and have tried every alternative, but I just keep coming back.  So instead of switching again, I’ve decided I should just start fixing the things that bug me, and I’ve started with the fact that I can’t get a feed of my tasks into iCal.  Since ICS feeds are read-only, there’s no way to be able to check off basecamp tasks in iCal, but I’ve started using Minco to track my time (great app, by the way), and it pulls in a list of items to track from your iCal to do list.  I’m sure you see where this is going– if I can push my Basecamp tasks into iCal, then Minco can see them.  Maybe you have another reason for wanting your tasks in iCal, but this was mine.  Anyway, thanks to Monte Ohrt’s Basecamp PHP API library, I was able to throw together an API tool to pull my tasks and push them out into an ICS feed in just an hour!  I’ve made this tool available so you can easily drop it into iCal and away you go.  Or, if you’d rather dig into it yourself, you can download my code from: http://tr.im/EjnN
(more…)