Chris Nizzardini, Salt Lake City Utah, Web Developer Specializing in LAMP+Ajax Since 2006

My Blog

Here is my awesome blog.

Archive for August, 2008

writing classes in javascript using mootools

Posted by chris on August 8th, 2008 Comments(0)

This is actually really simple and gives you some nice OOP functionality a web developer would not normally have in their web applications.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
var Customer = new Class({
	initialize: function(firstName, lastName, address, address2, city, state, zip, phone, email){
		this.firstName = firstName;
		this.lastName = lastName;
		this.address = address;
		this.address2 = address2;
		this.city = city;
		this.state = state;
		this.zip = zip;
		this.phone = phone;
		this.email = email;
	},
	quickSet: function(){
		this.firstName = $('firstName').value;
		this.lastName = $('lastName').value;
		this.address = $('address').value;
		this.address2 = $('address2').value;
		this.city = $('city').value;
		this.state = $('state').value;
		this.zip = $('zip').value;
		this.phone = $('ph1').value+$('ph2').value+$('ph3').value;
		this.email = $('email').value;
	}
});

In this example initialize is the constructor, which is required for a mootools class, where quickSet is a method I created for this class.

In ajax/dom/javascript ()

using functions in mysql where clauses breaks speed gains from indexing?

Posted by chris on August 8th, 2008 Comments(0)

I was conversing with a co-worker today and asked him to take a look at some queries of mine hoping he could determine why they were so sluggish. I had already ruled out a bad inner join, sub select, and lack of indexes. The query looked at a months worth of data using something like:

1
WHERE DATE(date_time) '2008-08-08'

For whatever reason this will cause MySQL (at least MySQL 4) to ignore the indexing on the date_time field. Changing your query to this:

1
WHERE date_time BETWEEN '2008-08-08 00:00:00' AND '2008-08-08 23:59:59'

Can save significant execution time. In my tests on a table with over 300,000 records this dropped by query execution time from roughly 4 seconds to .4 seconds, 10x faster! Using mysql functions in your select clause does not seem to negatively impact execution time.

In SQL ()