Some SQL fixes
Forgot a THEN
Merge pull request #1 from Quatrerwin/q-branch

Some SQL fixes from tyler
review of tyler's changes, I like what I see
a lot of little touch up, commiting now as tyler has and Idea so I should give him what I got
nothing to see here, just fixed a missing $ in a variable
fixed an issue where the thing was loading an outdated jquery mobile. Ithink I might be able to get this thing into beta tommorow