Back-end for Front-Enders: XML to MySQL – insert and update

Freelancing can take a developer in many directions that they wouldn’t get to go in a specific company role. The three years that I spent in front-end development taught me a lot about jQuery, CSS and conditional PHP but it really even touch on handling data. The terms ‘sanitize’ and ‘data object’ are still new-ish to me, gleaned from the lexicon of colleagues and peers. Nevertheless, it is the job of a freelancer to understand that anything is possible and then find out how to do it.

The problem:
I have an ftp folder with about 10 .xml files that get updated by a 3rd party every day at midnight. i need to a) initially insert them into MySQL and b) cron check daily for new new records and for records that need updated.

In my mind, it is a matter of breaking apart arrays and analysing them… but, I wanted a pro opinion on how it should be done. So I asked my friend Lloyd Leung what he recommended and he laid it out for me:

First, you will have to create a .php page

1.) validate the xml, make sure it’s correct. look into “tidy” in the php manual.
2.) load object if exists, or start a new object.
3.) validate the data object’s data.
4.) save the data object.
5.) done.

– Run the cron on your .xml at 2am, so it gaves them time to upload, and finalize the data.
– If at anypoint, something F’s up… send an email out to report the error as to what happened.

So, of course, this is perfectly clear but I still wanted to double check that I had my wording right. I asked exactly what he meant by ‘data object’ and was told that it’s a class, that would represent a single row in a database. Or ‘collection’ of data that is represented in the database.

For example:
– “human” would be an object.
– Human has “color of eyes”, “hair color”, “height”… and those are all properties of “human”.
– human->setHairColor(‘brown);
– human[‘hairColor’] or human->getHairColor(), would return “brown”

When you “setHairColor();” you can check if it’s a string, in a list of acceptable “colors”, if it’s “capitalized”, whatever business rules that need to happen.
So, now you’re dealing with a single class, that houses logicallly, all functions that are tied to “human”.

Thanks Lloyd! This was helpful for me.


Less Framework 3

Less Framework is a cross-device css grid system based on using inline media queries.

The core idea is to first create a default layout normally, and then additional layouts using inline media queries. Any browsers incompatible with media queries will simply ignore the additional layouts, and will only use the default one. The additional layouts will inherit any styles given to the default layout, so coding them is a breeze.

All four of the layouts included in Less Framework share a common column-width and gutter-width, which makes it easy to design them consistently. Also included are two sets of typography presets composed around a baseline grid of 24 px.


Google Voice vs. Skype

Google announces the release of a direct competition to Skype‘s web-to-phone service, Google Talk. with free calls to USA and Canada for the rest of 2010. Currently, when a call is made a charge of 10 cents appears next to your call history. My hope is that will be erased at the end of 2010, and I will no long be able to make calls until I have purchased credits to continue to make long distance calls at low rates.


Download all the links on a page

I was migrating a website containing about 100 links to pdfs on one page. I didn’t have access to the old site’s ftp so I needed a utility to speed up the process, instead of right-clicking on each file and saving the link manually.
I found a link to this on a very handy utilities list […]