Update and a Few Photos

I know it’s been a couple of months and I’m behind with photos. (What else is new?) We’ve had an fine past couple of months. In March, we headed up to Paramus to spend a couple of hours at the New Jersey Children’s Museum, where Kyle had a great time. At the end of March, Kyle started T-Ball. He really enjoyed it, especially since his best friend Robbie was on the same team.

We had a quiet Easter at home. In April, we hit the Somerset Patriots (minor league baseball team who plays about 30 minutes from us) Fan Fest. This included games for the kids and a game of old-fashioned baseball. Kyle didn’t want to stay long enough to run the bases like he did last year. In May, we visited the Bronx Zoo again. (We have a membership for the year, which pays for itself with only two trips. We try and do four for the year we are members.) For Memorial Day, Suzanne’s parents came to visit. It’s always nice when they come, though it’s likely to be a while before they get back as Suzanne’s sister Beth is due any day now.

The big thing last week was Kyle’s graduations from the YMCA’s Kinderwrap program and Kindergarten. It’s hard to believe he’s already that old.

Kinderwrap Graduation

Kindergarten Graduation

Kindergarten Graduation

Kyle just started summer camp at Oak Crest Day Camp today and had a wonderful time. He’ll be there for a total of 7 weeks this summer, but will go the YMCA’s program for the week before our trip out west as Oak Crest ends a week earlier. Next week we’ll be camping with my Mom in NH for a few days. Kyle has wanted to go camping for a while and this should be a good intro. We’ll have a tent, but we’ll see if we end up sleeping there or in the motorhome. Aside from our trip at the end of the summer, we don’t have any big plans for the summer. Undoubtedly we’ll have a few birthday parties, and we hope to hit the zoo one last time. Maybe by then I’ll have more recent photos posted. 🙂

Brief update and a few photos

It’s been a while since I did any kind of an update. Not that that much has changed in the past few months. We had a very nice Christmas, with Jack and Mary Lou coming up for some of the time. We both get the week between Christmas and New Years off, which is always nice. (Well … Suzanne actually has to take it as part of her vacation time as the plant is shut down.)

In late January, we had a wonderful birthday party for Kyle. It happened to be on the one day of snow we had all year, but the roads were decent enough to get around and no one was coming from very far. We had a science, mostly chemistry, themed party with a bunch of experiments making some kind of goo. Several people from my work loaned by stuff which was great. Suzanne did a wonderful job organizing it. I don’t have many photos as I was busy helping the entire time.

Kyle's birthday party

Kyle and Robby at Kyle's birthday party

Last weekend, Kyle had another party to go to at a bowling alley in Garwood. He had a great time. It worked out very well for us too as it was 4:30-6:00. Suzanne and I were able to leave a grab an early dinner at a nearby (excellent) Asian-fusion place by ourselves. Many kudos to Mikey’s parents. Sunday, we visited what will be Kyle’s day camp for most of the summer. It’s a really nice place (Oak Crest Day Camp), but not cheap. (At least his school year costs will drop a lot next year with full day school.)

Not too many plans for the near future. It looks like we’ll be heading our west to the Grand Canyon and southern Utah at the end of the summer. We’re still working on airline tickets, but we’re pretty excited. (Okay, maybe that wasn’t so brief.)

Extra: I had to toss in the one last photo of me at a recent metal (Megadeth & Motorhead) concert.

CS 601 – MySQL INSERT … SET syntax

While working on my project, I came across the following. The standard syntax for inserting items into a database is something akin to:

INSERT INTO tblMyTable (FirstName, LastName, Email, Phone)
     VALUES ('John', 'Doe', 'johndoe@gmail.com', '1234567890')

This is standard SQL. However, MySQL has an alternative syntax using SET which is similar to the UPDATE syntax:

INSERT INTO tblMyTable SET
       FirstName = 'John',
       LastName  = 'Doe',
       Email = 'johndoe@gmail.com',
       Phone = '1234567890'

I ended up using the alternative syntax throughout my project. Why? I felt it is much cleaner and easier to read than the standard syntax, especially when removing a column to insert. (When adding a column, it’s easy enough to add them to the end of the lists.) It should also greatly reduce errors from incorrect ordering between column names and values since they’re right next to each other. I realize that using MySQL specific syntax would break the site if it was moved to another database, but I don’t feel that was a concern for this project. In the real world, especially dealing with projects that are commercial and may/will grow larger, it might not be a good idea.

Here’s an example from my actual code:

$query = <<<EOT
    INSERT INTO tblReservations SET
        dtReservationDateTime = FROM_UNIXTIME($datetimeunix),
        intPartySize = {$_POST['numparty']},
        intCustomerID = "{$_POST['userid']}",
        vcReservationNameFirst = "{$_POST['firstname']}",
        vcReservationNameLast = "{$_POST['lastname']}",
        vcReservationEmail = "{$_POST['email']}",
        chReservationPhone = $phone,
        vcComments = "{$_POST['comment']}",
        dtReservationDateTimeMade = NOW()
EOT;

CS 601 – JQuery UI Datepicker – Blocking Dates

One of the things I wanted to do is to block certain dates from being enabled in the JQuery UI Datepicker widget. There is built-in functionality for blocking weekends, but not for particular dates, e.g., Christmas. Some web searching led me to a fairly easy solution. The widget has an option for providing a function to call before a date is shown. Here is my widget constructor:

$('#datepicker').datepicker({
                inline: true,
                showOn: "both",
                buttonImage: "/cafemarburg/images/calendar.jpg",
                minDate: +1,
                maxDate: +180,
                beforeShowDay: checkClosedDates
        });

checkClosedDates is a function that returns an array of the form [true/false, a class to add, a tooltip message], the last two being optional. It takes the date (as a Javascript object) as a parameter.
Here is the function call:

var closedFullDates = new Array(); // Used for one-time closures or irregular scheduled holidays
var closedYearlyDates = new Array('12-25','7-4'); // Used to regular holidays (e.g., Christmas)
var closedDaysOfWeek = new Array('0')
function checkClosedDates(date) {
 var blocked = false;
 var ymd = date.getFullYear() + '-' + (date.getMonth()+1) + '-' + date.getDate();
 var md = (date.getMonth()+1) + '-' + date.getDate();
 if ($.inArray(ymd,closedFullDates) > -1) {
     blocked = true;
 } else if ($.inArray(md,closedYearlyDates) != -1) {
     blocked = true;
 } else if ($.inArray(String(date.getDay()),closedDaysOfWeek) != -1) {
     blocked = true;             
 }
 if (blocked) {
    return [false,'dpClosedDate','Sorry, we are closed that day.'];
 } else {
     return [true];
 }
}

As can be seen, I use three separate arrays. One is for one-time events or events that change date year to year. Another is for dates that occur on the same date. The third is for days of the week.

CS 601 – PHP Multiline Strings

During the course of my project, I had many instances of needing to write very long strings, often when constructing moderately complex MySQL queries. There are several way to do this. One would be repeated each statements or assignment with .= . Another would be running the echo/assignment over multiple lines by using . at the end of each until the final one (ended with ; ). Example:

$mystr = 'Here is a really long line of text that runs to '.
         'more than one line';

I found a very clean and convenient way is to use PHP’s heredoc syntax. Here’s an example:

$query = <<<EOT
        SELECT * FROM tblOrderItems
        INNER JOIN tblFoodItems
                ON tblFoodItems.intFoodItemID = tblOrderItems.intFoodItemID
        INNER JOIN tblFoodCategories
                ON tblFoodCategories.intFoodCategoryID = tblFoodItems.intFoodCategoryID
        INNER JOIN tblFoodCategoryOrder
                ON tblFoodCategoryOrder.intFoodCategoryID = tblFoodCategories.intFoodCategoryID
        WHERE intOrderID = {$order['intOrderID']}
        ORDER BY tblFoodCategoryOrder.intFoodCategoryOrder, tblFoodItems.vcFoodItemName
EOT;

There’s a few things to note:

  • The EOT is arbitrary as long as both instances are the same. (I use EOT for “end of text”.)
  • Variables can be included in the string. A simple variable is simply included as $myvar. Here, I use the {} to separate out a “complex” variable. (I didn’t realize this could be done until later on, so for some of my earlier instances, I set it to a simpler variable immediately before the heredoc declaration.)
  • The terminator (here EOT;) MUST be on a line by itself with no leading or trailing whitespace. This cannot be emphasized enough. Leading whitespace is pretty easy to spot, but several times NetBeans added trailing whitespace which wasn’t obvious in and of itself. (NetBeans does color the heredoc string differently, so you will see the “carry over”.) I finally got in the habit of checking.

PHP ≥ 5.3.0 also has the nowdoc syntax. It’s very similar to heredoc except is uses $myvar = <<<‘EOT’ (note the single quotes). The difference is that variables are not expanded akin to standard single quoted strings.

CS601 – Delete Current Element from DOM

At one point a few weeks back (for one of the homeworks), I could not figure out how to delete the current element from the DOM while working in Javascript. Some searching turned up the following solution:

detaildiv.parentNode.removeChild(detaildiv);

Basically, you get the element’s parent node, then deleted the specified child node, this being the element. I’m not sure this the standard method, but it works and is clean. (This was before we were looking at JQuery, so perhaps it has a better solution.)