jump to navigation

The Four Core PHP Development Principles November 13, 2009

Posted by chris in : rant , add a comment

We’ve all written bad code. Look at the code you wrote 2 years ago, 6 months ago, or heck even yesterday. When I do this I find that I failed to follow my 4 core development principles. That’s okay we are not perfect, but we should always be striving to accomplish something more than just getting the job done when we program. Just getting the job done in a quick manner will almost always produce poor quality code that at best doesn’t scale and at worst isn’t secure.

1. Scalable
Big apps get more lovin’. If your code isn’t scalable, it probably sucks.

What do I mean by scalability? One way to look at scalability is how easy is it to add in new features to your application. The best way to create scalable code is through planning, understanding what you want the application to be when its complete, where you want the application to be in 3 years, and what other markets/tasks you might want the application to handle down the road.

(more…)

MooTools Table Sorter version 0.9.5 October 13, 2009

Posted by chris in : ajax/dom/javascript , add a comment

I’ve added some additional features to TableSorter (originally featured here). I fixed some bugs in the removeParameter function, added a removeAllParameter function, and added a reloadView function. The new version has nicer default CSS and provides you with a pretty default table reload feature.

Check out the demo page. Post any questions here please.

mysql get total rows in query with sql_calc_found_rows August 13, 2009

Posted by chris in : SQL , add a comment

The MySQL SQL_CALC_FOUND_ROWS function is a nice way to return how many rows were returned in the query. There has been a lot of discussion in the PHP.net entry on mysql_num_rows regarding this function. The debate centers around whether its more effecient to use MySQLs built in functionality or whether its more effecient to run the same query again using the COUNT() function.

For me, its hard to determine which way is better. Usually its better to leverage your database engine than code. There is not an easy way to tell how database cache plays into this either. I feel using SQL_CALC_FOUND_ROWS is the better option, it eliminates a few extra lines of code, and prevents you from having to update multiple queries. Whether there is a performance penalty in either case is debatable, if its even noticeable…

SELECT SQL_CALC_FOUND_ROWS * FROM tbl_customer WHERE entry_date > '2009-01-01';

In a separate query run this (I believe this is connection dependent, so they must be run in conjunction with each other within the life of the same connection).

SELECT FOUND_ROWS() as totalRows;

best way to load your JavaScript July 30, 2009

Posted by chris in : ajax/dom/javascript , add a comment

Interesting article over at Ajaxian on loading your javascript code. I’m not sure this is the best way in all cases, but when you’re coding in a world of frameworks, multiple js files, wysiwyg editors, and framework plugins and widgets it definitely makes sense in many circumstances.

google wave, next generation collaboration platform, google exchange killer July 24, 2009

Posted by chris in : rant , add a comment

Reading Slashdot I came across this article on Googles latest yet-to-be-released product called, Google Wave.

http://developers.slashdot.org/story/09/07/22/220226/Google-Wave-Reviewed

I was interested enough to sit through the 1 hour video demo on the product and it was worth every minute. I am thoroughly ecstatic about this product and the Google Wave API makes the possibilities endless. Think about all those iphone style apps or all those great FireFox Addons rolled into an enterprise (or something great for you and some friends) collaboration suite.

In thinking about Wave, Google thought about what they would include in email if they could completely rewrite it today. What they ended up doing is making email interactive like an instant messenger client, to the point where you can see what recipients (yes thats plural you can add multiple people to an email) is typing character by character as it happens real time. Now say you add a new person to a “thread” that has hundreds of responses, enter the playback feature. You can playback the life cycle of the thread, message-by-message and edit-by-edit from beginning to the most recent response. This thing is jam packed with other neat features like a slick drag and drop photo gallery (gears only right now but they are pushing to get it adopted into HTML 5), spell checker, setting pieces of a thread private etc.

The whole thing is open source so you’re not locked into Google as your Wave vendor. You can install it at home or work and modify the code to tailor the Wave to your organizations needs. If modifying the application is a bit much you can tie into the Wave API and create your own extensions. If you have an hour and twenty minutes to kill I would watch the demo, it really is awesome!

adventures in linux printing, set default printer and firefox command line print July 23, 2009

Posted by chris in : linux, php , 2comments

We are in the process of redesigning our packing slips that get sent out to customers with each order. The previous developer went with a solution, html2ps, that has shotty support for CSS and design principals in general. The designer and I decided we needed something else. After trying numerous solutions, a co-worker suggested I give FireFox command line print a try.

(more…)

firefox 3.5 fails – bug with ajax callback onreadystatechange July 17, 2009

Posted by chris in : rant , add a comment

I first noticed this bug a few days after upgrading to FireFox 3.5. When you fire an XHR request, the callback function is not being executed when the request completes itself. Instead you see an onreadystatechange error in Firebug.

There have been several bugs reports on this:

http://www.nczonline.net/blog/2009/07/09/firefox-35firebug-xmlhttprequest-and-readystatechange-bug/
http://www.ghastlyfop.com/blog/2007/01/onreadystate-changes-in-firefox.html

My advice is don’t upgrade too FireFox 3.5 until they have released a patch for this bug. Its incredibly annoying to keep retrying your XHR request until it finally succeeds knowing your code is just fine. I have downgraded both my systems to FireFox 3.0.11. My bigger concern is how this ever got passed of by QA?

new TableSorter mootools widget for sorting tables July 9, 2009

Posted by chris in : ajax/dom/javascript , add a comment

Please see the version 0.9.5 blog post
(more…)

zend studio 6 fails – going back to zend 5.5 June 6, 2009

Posted by chris in : rant , 3comments

Zend, the PHP Company, took a major step back with their PHP IDE when they moved it too the eclipse platform. I’m not a fan of eclipse, I don’t even like using it for Java development – which its built for. Zend Studio 6 is slow, clunky, the user interface is confusing, the FTP component is horrible.

If you can name it, Zend 5.5 beats Zend 6 at it, except for javascript support. However, I only need a JavaScript IDE for when I am doing heavy JavaScript coding or debugging. The worst part about Zend Studio 6 is the FTP component. Every time you save a file – it refreshes the folders and closes them all. So you can to open the folder again and wait everytime you make a save! Finally I decided to update the program hoping they had fixed this bug. When I updated to the latest version I was no longer able to connect to most of the FTP servers I had (roughly 10), one of which was to this domain.

At the point I uninstalled and went back to Zend 5.5 and wrote this article. Flat out, Zend Studio 6 sucks.

mysql with rollup for a easy grouped total columns in result set June 4, 2009

Posted by chris in : SQL , add a comment

Using the WITH ROLLUP modifier in queries using GROUP BY will add an additional row to the result set which sums all columns. This prevents you from having you to write code which adds each column in your programming language.

Description from the Mysql Reference Manual

The GROUP BY clause allows a WITH ROLLUP modifier that causes extra rows to be added to the summary output. These rows represent higher-level (or super-aggregate) summary operations. ROLLUP thus allows you to answer questions at multiple levels of analysis with a single query. It can be used, for example, to provide support for OLAP (Online Analytical Processing) operations.

Example

SELECT
	DATE(dateTime) AS order_date, count(*) as shipments, sum(shipping_total) as shipping_total, sum(hasShipAmt) as hasShipAmt, sum(shipping_total)-sum(hasShipAmt) AS revenue
FROM
	tbl_my_orders
WHERE
	dateTime BETWEEN '$startDate' AND '$endDate 23:59:59'
GROUP BY
	order_date WITH ROLLUP