Transform a MySql request to array

function requestToArray($req) 
	{
 
		$this->result_rows = 0;
		$this->result_cols = 0;
		$this->result_array = null;
		$this->error = null;
 
		$result = mysql_query($req);
 
		if (!$result) {
			$this->error = ($req . " - " . mysql_error());
			print("The request: $req didn't execute correctly: ".mysql_error()."\n");
			return null;
		}
 
		$this->result_rows = mysql_num_rows($result);
		$this->result_cols = mysql_num_fields($result);
 
		$this->result_array = array ();
		while ($tab = mysql_fetch_assoc($result)) {
			array_push($this->result_array,$tab);
		}
 
		return $this->result_array;
 
	}

VIF: Very Important Functions

Comparison Functions and Operators:

IS NULL, IS NOT NULL

MySql Manual

Control Flow Functions:

SELECT IF(1>2,2,3); -> 3
SELECT IFNULL(NULL,10);  -> 10

MySql Manual

TIMESTAMP Properties:

HOUR(this.date)
SECOND(this.date)

MySql Manual

Date and Time Functions:

DAYOFWEEK(this.date)
DAYOFMONTH(this.date)
DAYOFYEAR(this.date)

MySql Manual

Prototype: Ajax Controller

To load Prototype and Scriptaculous object library:

<script src="../javascript/prototype.js" type="text/javascript" language="JavaScript"></script>
<script src="../javascript/scriptaculous.js" type="text/javascript" language="JavaScript"></script>

Now the Controller class and some lines to use it:

<script language="Javascript" type="text/javascript">
ajax_controller = Class.create();
ajax_controller.prototype = {
	initialize : function(url, target, name, parameters) {
		this.url = url;
		this.target = target;
		this.method = 'post';
		this.name = name;
		this.js_stop = name + '.stop()';
		this.parameters = 'STOP=' + this.js_stop + '&' + parameters;
 
		this.xml_Http_Object = null;
		this.running = false;
	},
	start : function() {
		if (this.xml_Http_Object == null) {
			this.xml_Http_Object = new Ajax.PeriodicalUpdater(this.target,
					this.url, {
						method : this.method,
						encoding : 'ISO-8859-1',
						parameters : this.parameters,
						onSuccess : this.success_handler,
						onInteractive : this.interactive_handler,
						onComplete : this.complete_handler,
						onLoading : this.loading_handler,
						onLoaded : this.loaded_handler,
						evalScripts : true,
						asynchronous : true,
						frequency : 0.8,
						decay : 0.1
					});
			this.running = true;
		} else if (!this.running) {
			this.xml_Http_Object.start();
			this.running = true;
		}
	},
	stop : function() {
		if ((this.xml_Http_Object != null) && (this.running)) {
			this.xml_Http_Object.stop();
			this.running = false;
		}
	},
	change_parameters : function(parameters) {
		this.stop();
		this.xml_Http_Object = null;
		this.parameters = 'STOP=' + this.js_stop + parameters;
		this.start();
	},
	success_handler : function(request) {
 
	},
	interactive_handler : function(request) {
 
	},
	complete_handler : function(request) {
 
	},
	loading_handler : function(request) {
 
	},
	loaded_handler : function(request) {
 
	}
}
 
var begin_date;
var end_date;
var my_controller = new ajax_controller('../include/stats_writer_response.php',
		'div_result_open', 'my_controller', 'date_de=' + $F('date_de')
				+ '&date_ah=' + $F('date_ah'));
 
Event.observe('sp_btn_start', 'click', start_me, false);
Event.observe('sp_btn_stop', 'click', stopp_me, false);
//Event.observe('toDate', 'click', toDate, false);
 
function start_me() {
	my_controller.start();
}
 
function stopp_me() {
	my_controller.stop();
}
 
function toDate() {
	my_controller.change_parameters('&begin_day=' + $F('begin_day')
			+ '&begin_month=' + $F('begin_month') + '&begin_year='
			+ $F('begin_year') + '&end_day=' + $F('end_day') + '&end_month='
			+ $F('end_month') + '&end_year=' + $F('end_year'));
}
</script>