Thursday, 14 June 2007

W3C Validator is not infallible

If you want your pages to be considered valid, you probably use W3C's mark-up validator. This thing is pretty smart - even though some of its messages don't make a lot of sense.

I used to think it was infallible, but I should have known better. Like CSS and JavaScript inconsistencies across browsers, the W3C validator is also not quite perfect.

I recently used to it validate some php pages. Obviously, the validator only validated the X/HTML that was rendered, but it failed to pick up the following slips.

I had to edit what was a textarea, to make it a simple text input box:

ORIGNAL CODE:

<td class="hr"><textarea name="street_address_1" rows="4" cols="35" maxlength="100"><?php echo str_replace('"', '"', trim($row["street_address_1"])) ?></textarea></td>


EDITED CODE:

<td class="hr"><input maxlength="100"
name="street_address_1"></textarea></td>


Even though I had failed to remove the </textarea> tag in my edited version, my page validated.

On top of this, I had a few instances of
<input type="checkbox" value="Yes" name="is_publisher">

The validator ignored the fact I hadn't closed the tag, and I'm pretty sure that's a basic requirement of XHTML 1.0 Strict Mark-up!?

Sunday, 10 June 2007

MySQL says "boo" to booleans

MySQL is supposed to be "all that". Simpler than SQL yet just as powerful (and hey, it's free, so I ain't complaining here)... however, I was pretty surprised to find that there's no data type called "boolean" in MySQL. If you want to do something as simple as store a 'yes' or 'no', you've got to use the enum data type and then create a string of values that will represent your options, eg.

For yes/no radioboxes on a form, you'll need to use
enum('1', '0')
as your data type, where 1 = 'yes' and 0 = 'no', but you could use whatever labels you wanted, eg. 999 = 'yes' and 666 = 'no'.


Mind you, enum is pretty cool, because unlike the narrowminded boolean, enum will allow you to extend your list of options, eg.

For a form with a drop-down box containing the following options:
- Yes
- No
- Occasionally
- Prefer not to answer

You could use
enum('1', '0', '2', '3')
as your data type.

In this example, 'Yes' = 1, 'No' = 0, 'Occasionally' = 2, and 'Prefer not to answer' = 3.

Thursday, 7 June 2007

Please explain indexing...

So the DMT class is over but I figure I'm gonna do a few more blog posts - I just might pass this subject if I blog on the things I thought were interesting 10-12 weeks ago... but as for this blog, it's about something I just learnt (this betrays the status of my 'System Build')... indexing in MySQL, what a neat function. Now I understand how clever uses of the index feature can speed up data retrieval in a database.

Thank you Ian Gilfillan for explaining this in "Optimizing MySQL: Queries and Indexes".

Basically, the index feature allows the quick look up of data. For example, rather than scouring an entire databases for someone's name, if you index the 'firstname' and 'lastname' columns of your 'contact' table, when you run a name query, these columns get queried first - so rather than looking through your entire database until your query gets lucky, it looks straight at where the data sits.

Ian also covers the EXPLAIN query in MySQL, which enables you to QA just how efficiently you have used the index feature. I know this is a bit late for a lot of my fellow students to take advantage of, but it's a handy tip nonetheless.