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

$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

	//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));
} 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');
	$data = file_get_contents("./tester.txt");
	$data = unserialize($data);
	echo $at->GenerateTable();
	//echo "<pre>";


//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));


Return current item: Ajax Table Edit