I just posted photos of Kyle from November & December including our visit to the Sterling Hill Mining Museum and Christmas. Now I’m all caught up, just in time for his birthday party this weekend.
|
|||||
|
I just posted photos of Kyle from November & December including our visit to the Sterling Hill Mining Museum and Christmas. Now I’m all caught up, just in time for his birthday party this weekend. 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;
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.
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. 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:
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. 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: I’m a bit behind in blogging for class due to time constraints. I’m spending most of my free time working on my project. I have a bunch of ideas in the queue, but here’s one I just used tonight. One aspect of the project requires a sortable table. Not easy to implement on my own, but I found the very nifty JQuery UI Tablesort plugin. This is pretty cool and pretty easy to implement. I’ll include some snippets from the page which shows the employees as list of all reservations. Here is the JS code which creates the object: // add parser through the tablesorter addParser method The first block is simply a function to allow me to sort the reservation status (e.g., has the party arrived, have they been seated) using an ordering index regardless of the text for the status. (E.g., I would want “Made” sorted before “Arrived”.) The second block actually creates the applies the tablesorter object to the HTML table with the ID of restable. This table is a plain old HTML table with the addition of the class of tablesorter. You can also download the themes from the site, put them in your CSS directory, and then include that in your header. With all that you get the following (on load):
If you click the Last Name column:
If you click the Date/Time column:
It does the date correctly automatically. (Verified as 11/30/2011 12:00 PM sorts before 11/30/2011 01:30 PM and before 01/20/2012 07:45 PM. If it was a simple text-based sort, this would not be the case as 0 comes before 1.) It can also do multicolumn sort and a multitude of other things which I have not explored. I’m almost all caught up now. I just finished uploading photos from September & October. Included are photos from Kyle’s first day of kindergarten and a few from Halloween. Hopefully I’ll have the last few (from early November) up tomorrow. I just finished posting the batch from July and August. This also includes photos from September from our trip to Vermont to have them all included in the same album.
I know I have been very remiss in not posting recent photos of Kyle. (The most recent ones were posted in April.) I have finally managed to go through and tag/catalog all the ones I have (up to a couple of weeks back). I’ll be posting them over the next few days. Please keep in mind that in order to finally catch up, I decided to simply batch process all the images, so they may not be up to the usually standards. (Normally, I manually process each image, but that’s quite time consuming.) Anyway, the first batch is up at Kyle: May & June 2011. Here’s a couple of images:
|
|||||
|
Copyright © 2012 sanschagrin.com - All Rights Reserved |
|||||