Location: PHPKode > scripts > Ajax Table Edit > ajax-table-edit/AdvATE/AdvATEexample2.php
<?php
//ini_set("display_errors", "1");
//ini_set("error_reporting", "E_ALL");

/*
	This is another example...closer to "real world" usage.
	I created a small address book type thing, that is updated completely
	by ajax.  You can add on to this by including links for add/remove...I'm
	working on integrating this into the next version.
*/

include("./AdvATE.class.php");
$at = new TableEditor;

extract($_POST);

if ($FormRequest) {

	$at->SetForm('name','text');
	$at->SetForm('address','area');
	$at->SetForm('phone','text');
	$at->SetForm('phonetype','radio',array('Home' => 'Home', 'Work' => 'Work', 'Cell' => 'Cell'));
	$at->SetForm('sex','radio', array('Male' => 'Male', 'Female' => 'Female'));

	echo $at->HandleFormRequest($_POST['type'], $_POST['old']);
	
} else if ($FormSave) {
	
	$data = file_get_contents("./test2.txt");
	$data = unserialize($data);

	$data[$rowid][$colid] = $new;

	$open = fopen("./test2.txt", 'w');
	fwrite($open, serialize($data));
	fclose($open);
	
	echo $new;
	
} else {
	
	//the display properties for the odd and even rows
	$odd = array('style' => 'background-color: #CCCCCC;');
	$even = array('style' => 'background-color: #EEEEEE;');

	//the display properties for the overall table
	$table = array('align' => 'center', 'cellpadding' => '3', 'cellspacing' => '0', 'width' => '50%');

	//table column header information
	$headers = array("Name", "Address", "Phone", "Type", "Sex");
	$headerattrib = array('style' => 'background-color: skyblue');
	
	$at->SetEvenRowAttribs($even);
	$at->SetOddRowAttribs($odd);
	
	$at->SetTableAttribs($table);
	
	$at->SetHeaderAttribs($headerattrib);
	$at->SetHeaders($headers);
	
	$at->SetSubmit("AdvATEexample2.php");
	
	if (file_exists("./test2.txt")) {
		$example = file_get_contents("./test2.txt");
		$example = unserialize($example);
	} else {
		include("example2data.php");
		$example = $data;
	}
	
	/*
		for this example, I formated the data similar to how it would come from
		a database query...do a print_r on it to see
		
		because of that, we have to do some prep first
		
	*/
	
	$data = array();
	
	foreach ($example as $id => $row) {
		$data[$id]['name'] = array('data' => $row['name'], 'input' => 'name');
		$data[$id]['address'] = array('data' => $row['address'], 'input' => 'address');
		$data[$id]['phone'] = array('data' => $row['phone'], 'input' => 'phone');
		$data[$id]['phonetype'] = array('data' => $row['phonetype'], 'input' => 'phonetype');
		$data[$id]['sex'] = array('data' => $row['sex'], 'input' => 'sex');
	}
	
	$at->SetData($data);
	
	echo $at->GenerateTable();
	
	//echo "<pre>";
	//print_r($data);

}

?>
Return current item: Ajax Table Edit