Monthly Archives: March 2006

Project Two: Update

Quizzes are done! I’ve spent tha past few days working on those and cleaning up the sidebar. I wrote a seperate php file for the sidebar that has intelligence for displaying the proper menu items based on the user. I manually added this logic to the seperate pages previously. Now I simply include them.

The only think remaining is my Managers page. I laid out the different information that I want to display.

  • Outstanding Orders – These are orders that haven’t been delivered yet. From this list, the manager will be able to modify the estimated delivery date.
  • Today’s Shipped Orders – A list of the orders that were delivered today.
  • Today’s Scans – A list of the scans for the day, ordered by tracking number.
  • History – This allows a manager to view the orders shipped for the given month with an option to see the scans too.

I decided to take my time on this report section, so maybe I’ll get motivated and do some javascript that allows the user to expand orders to see their details and/or scans. We’ll see.

Project Two: A sensible use of XML

Although a lot of package sites offer to send you emails with tracking information, many people still don’t want to use it. They prefer to poll the site themselves by refreshing their browser every hour or so manually. So I decided to make tracking information available as an RSS feed. I generate an RSS feed for each tracking number via PHP. It was quite simple to do, but I felt it was a sensible use of XML.

From the tracking result page, I’ve added the alternate link for the RSS version of the page. Users with Mozilla will see the RSS icon in the address bar. I may add an RSS icon on the page for IE users.

Each scan results in a new item in the RSS feed. If the user clicks on it, then it will launch their browser to the tracking result page to an anchor on the exact column in the scans table.

Project Two: Getting a Date()

Client-side validation of forms that allow users to input dates can be a tricky thing. I searched all over for some simple JavaScript to do the trick. I found a lot of junk, but I finally turned up an elegant solution. JavaScript has a Date object that you can use to create a date based on the year, month, and day. To know if one of your inputs is out of bounds, you can create a date then pull that year/month/day from that Date and see if it’s the same as your input. This is because passing 2000-12-40 will actually return 2001-1-9.

PHP has similar capabilities. I had to automatically increment some dates, so I used mktime() to create the date, then I converted it to unix time and added the appropriate amount of seconds. Then I converted it back to time and printed it in the format that MySQL needed.

Project Two: Logging in…and out

I’ve fully implemented the login feature. I really wanted to get this working before finishing work on the scans table, because I wanted the employee and the manager page to show up only for the right class of user. I’ve got three user classes:

  • usr
  • emp
  • man
  • adm

A user can create their own account, but their user class will automatically be set to usr. The admin can create additional users with the other user classes, including another adm. If I get industrious, I may make a complete user editor.

I’ve made the change to attach a user to an order, but I’m not sure if I’ll get the time to add the feature where a user can quickly find all of their orders. Therefore this feature is primarily to show the extra menu items and pages for different user classes. An employee will be able to add a scan for an order. A manager will be able to generate reports. And the admin can add users as mentioned above as well as reinstall the site.


AUTO_INCREMENT sounded like a quick kill for allowing MySQL to generate the new Tracking IDs for me. I ran into two problems. First I tried to get the newly generated ID through the PHP function, mysql_insert_id(). Well, since our Tracking IDs are 11 digits, they grow outside of the boundaries of a standard MySQL INT and require a BIGINT. No big deal, exept this PHP function only returns up to a PHP int. So I had to rely on the MySQL function, LAST_INSERT_ID(), in a standard query. So I had to execute the query, get the resulting row, and use that.

I was testing LAST_INSERT_ID() in my mysql client as I was adding information with the webapp, and it was failing. Apparently it’s only reliable within the same session that is inserting the rows.

Project Two: Things learned from

SELECT MAX (id) AS id FROM my_table – Allows you to select the maximum value for a field. I can use this to add the newest tracking number when a new order is added.

AUTO_INCREMENT – This is, however, likely a better route to take for adding a new row and getting a new tracking number as a result. You can then get the last auto incremented value with LAST_INSERT_ID().

I’ll likely use an integer for the tracking number with a maximum length and a zero fill option.

Project Two: MySQL

Sorted out how to use MySQL queries with PHP. It’s rather convenient, especially when combined with the easy of form processing of PHP. I’ve got my installation page working. I just need to add in support for the rest of my tables. When I wrap that up, I’m going to need to clean the code up. It’s hard to find a style with PHP, especially with the XHTML mixed in. I’ll have to search for some good examples. I’m still uncertain how to seperate the XHTML from the PHP. I guess I can read in pieces of XHTML and output them with PHP, but that seems a little kludgey.