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


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

if (isset($_POST['new'])) {
	//You can choose to handle the data processing part of your script
	//this way, where it is all in one page.
	//Just make sure that you either return nothing on success,
	//or you echo out "true", otherwise it will error
	
	extract($_POST);

	//the script returns three values:
	//$rowid: the id for the row
	//$colid: the value for the column
	//$new:   the value that was typed into the text input
	
	$data = file_get_contents("./tester.txt");
	$data = unserialize($data);

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

	//if this were a database, you could use the following SQL statement:
	//UPDATE $tablename SET `$colid` = '$new' WHERE id = '$rowid'
	//you should do some verification on the data input by the user.
	
	$open = fopen("./tester.txt", 'w');
	fwrite($open, serialize($data));
	fclose($open);
	
} 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("Col 0", "Col 1", "Col 2", "Col 3");
	$headerattrib = array('style' => 'background-color: skyblue');
	
	$at->SetEvenRowAttribs($even);
	$at->SetOddRowAttribs($odd);
	
	$at->SetTableAttribs($table);
	
	$at->SetHeaderAttribs($headerattrib);
	$at->SetHeaders($headers);
	
	$at->SetSubmit("example.php");
	
	$data = file_get_contents("./tester.txt");
	$data = unserialize($data);
	
	$at->SetData($data);
	
	echo $at->GenerateTable();
	
	//echo "<pre>";
	//print_r($data);
}


/*

//comment out everything above, and uncomment this to rebuild the sample data

for ($a = 0; $a < 20; $a++) {
	for ($b = 0; $b < 4; $b++) {
		$n[$a]["row" . $b] = "Row $a column $b";
	}
}

$open = fopen("./tester.txt", 'w');
fwrite($open, serialize($n));
fclose($open);

*/

?>
Return current item: Ajax Table Edit