Jun 21, 2010 23:49
I'm getting to the point where I can actually have an idea and make it happen even if it's not just a variation on one of the projects in the books I've been working through. Friday i decided it would be cool to have a series of checkboxes, one for each day of the week, then take the checked values and have the day names output as a string with contiguous blocks of 3 or more days using the first and last day names in the block with the word "through" in between, and commas separating the rest of the day names.
For example, if the user checked Monday, Wednesday, Thursday, Friday and Sunday, the output would be "Monday, Wednesday through Friday, Sunday."
It doesn't seem like much, but hey, I'm a noob.
After I made it work I went back an used more generic variable names and modified it so it will work with any sequence of checkboxes (no matter how many) simply by setting up a couple of variables correctly. Next I will try making it into a function.
Ultimately this part of the script will be formatting data coming from a database table. The checkboxes will be for the user to select days. When the days come out of the database I mean to present them the way this script does.
I'm still a little slow at the beginning of a process like this, as there are lots of things I don't know and there are usually several ways to use the logic to solve a problem, but I'm getting faster at writing the code and troubleshooting it. It feels pretty good!
The only downside is now when I'm doing mundane tasks like making dinner I think things like "SELECT vegetables FROM refrigerator WHERE type = 'salad_fixin\'s' AND status <> 'rotten';"
php,
scripting