Location: PHPKode > scripts > Template Interface Engine > template-interface-engine/sample5.php
<?php
	include 'interface.class.php';
	include 'mysql.class.php';

	$fields = array(
				array('Name', 'ordername', 'imgname'),
				array('Address', 'orderaddr', 'imgaddr'),
				array('City', 'ordercity', 'imgcity'),
				array('staten', 'orderstate', 'imgstate'),
				array('Email', 'orderemail', 'imgemail'),
				array('Birthday', 'orderbirth', 'imgbirth')
			);

	$tmpl = new CInterface('sorting.html');

	$mydata = new Tmysql;
	$mydata->SetConnection('localhost', 'root', 'kreators', 'interface_sample');

	if(isset($_POST['order'])) {
		foreach($fields as $field) {
			$tmpl->{$field[1]} = ($_POST['sortby'] == $field[0])?(($_POST['order'] == 'asc')?'desc':'asc'):'asc';
			$tmpl->{$field[2]} = ($_POST['sortby'] == $field[0])?(($_POST['order'] == 'desc')?'desc':'asc'):'';
		}
	} else {
		foreach($fields as $field) $tmpl->Var[$field[1]] = 'asc';

		$tmpl->ordername = 'desc'; // set for default ordering
		$tmpl->imgname = 'asc';
	}

	$mydata->Connect();
	$mydata->SetQuery(
				'select a.*, s.State staten from addressbook a, states s '.
				'where s.StateID=a.State order by '.
				(isset($_POST['sortby'])?$_POST['sortby']:'Name').' '. // default ordering is here
				(isset($_POST['order'])?$_POST['order']:'asc')
			);
	$tmpl->row = mysql_to_array($mydata->Query());
	$mydata->Close();

	$tmpl->RegisterFunction(create_function('$r', 'return ($r + 1);'), 'row_no');

	$tmpl->Output();
?>
Return current item: Template Interface Engine