I’m going to add more to this later, but for now… SQL CASE scenario #1 Ever wanted to offer quantity discounts for shoppers? Here’s an example of a trivial implementation of the CASE condition in MySQL to get the job done. mysql> SET @cart_quantity := 3; Query OK, 0 rows affected (0.00 sec) mysql> select [...]
Recently I was challenged on the fly to come up with an example of a factory pattern. Here is the result: /** * Database Connection Example * @author randymelder */ interface DatabaseConnection { function connect(); } class MySQLDatabaseConnection implements DatabaseConnection { var $link; var $user; var $pass; var $host; function __construct($host,$user,$pass) { $this->user = $user; [...]
While looking for a hip-pocket sorting, algorithm, I found some sample code here and thought it was perfect the way it was. function quicksort($seq) { if(!count($seq)) return $seq; $pivot= $seq[0]; $low = $high = array(); $length = count($seq); for($i=1; $i < $length; $i++) { if($seq[$i]