Subject Grid data entry (sample)
Author Almond
I raised the topic, many thanks for all the people give me comment/advise
on this.

Attached is a small sample which I do my test. The remaining part would be
batch processing on the back end.

The java code logic is from Mr. Milan Babuskov and Mr. Rajesh Kumar give me
guidelines on the update logic. Thank you very much.

I'm new to php, please give me comments and amendment on this sample.

Best regards,

Almond Wong

// Author : Almond Wong, almond@...
// Description : Grid type data entry for a sub-set of data.
//
// Please give me your amendment on this program if you think it is useful.
// Thanks in advance.
//
//

<SCRIPT LANGUAGE=Javascript>
function changedField(frm, x) {
modi = eval("frm.MODI" + x + ".value = 1");
window.status = "LAST ROW MODIFIED - " + x;
}
</SCRIPT>

<?php
function col_heading() {
global $fn, $field_count, $debug;
$rec_table = "<table BGCOLOR=\"d0d0d0\" >";
$rec_table .= "<tr>";
$rec_table .= "<td>IDX</td>";
if ($debug) {$temp = "MODI";} else {$temp = '';}
$rec_table .= "<td>$temp</td>";
for ($i = 0; $i <= $field_count; $i++) {
$rec_table .= "<td>$fn[$i]</td>";
}
$rec_table .= "</tr>";
return $rec_table;
}
require_once 'OPIC_db.php';
require_once 'PEAR_DB.php';
global $rec_key;
$nl = "\n"; $br = '<br>';
$debug_st = '<center><font color="RED"><B><U>';
$debug_end = '</U></B></font></center>'. $br;
$debug_msg = $debug_st. 'Debug is on'. $debug_end. $br;
if (!isset($debug)) {$debug = 0;}

$filename = 'color_dtl';
$filter = '';
$fn[] = 'color_dtl_stock_codename';
$fn[] = 'color_dtl_color_codename';
$fn[] = 'color_dtl_quantity';
$fn[] = 'color_dtl_unit_price';

$field_count = sizeof($fn) - 1 ;
$Q = 'select ';
for ($i = 0; $i <= $field_count ; $i++) {
$Q .= $fn[$i] ;
$fn[$i] = strtoupper($fn[$i]);
if ($i < $field_count) {$Q .= ', ';}
}
$Q .= " from $filename ";
if ($filter != '') {$Q .= "where $filter ";}

if ($debug) {echo $Q. $nl;}

echo "<form method=\"post\" action=\"./Grid_a.php\">";
if (!isset($submit)) {
$DB_Query = $DB_Connect->Query($Q);
$rec_table = col_heading();
$j = 0;
while ($ROW = $DB_Query->fetchRow(DB_FETCHMODE_ASSOC)) {
$asize = sizeof($ROW) - 1;
$avalues = array_values($ROW);
$rec_table .= "<tr>";
$rec_table .= "<td>$j</td>";
if ($debug) {$temp='text';} else {$temp='hidden';}
$rec_table .= "<td><input type=$temp size=4 name=\"MODI".
$j."\" value='0'></td>";
for ($i=0; $i <= $asize; $i++) {
$rec_table .= "<td><input type=\"text\"
name=\"$fn[$i]"."$j\" onChange=\"changedField(this.form, $j)\"
value=\"$avalues[$i]\" ></td>";
}
$rec_table .= "</tr>";
$j++ ;
}
$rec_table .= "</table>";
$rec_table .= "<br><br>";
echo $rec_table;

echo '<input type=submit> <input type=reset>'. $br;
echo "<input type=\"hidden\" name=\"debug\" value=\"$debug\">";
echo "<input type=\"hidden\" name=\"submit\" value=\"update\">";
$DB_Query->Free();
$DB_Connect->Disconnect();
exit ;
}

$var = $fn[0]. '0';
if ($submit == 'update') {
echo "<h1>Update</h1>";
$rec_table = col_heading();
$j = 0 ; $var=$fn[0].'0' ;
while (isset($_REQUEST[$var])) {
$rec_table .= "<td>$j</td>";
if ($debug) {
$var = 'MODI'. $j;
$rec_table .= "<td>$_REQUEST[$var]</td>";
}
$var = $fn[$j]. "rec_". $j. "_" . $rec_key[0];
for ($i = 0 ; $i <= $field_count ; $i++) {
$var = $fn[$i]. $j;
$rec_table .= "<td>$_REQUEST[$var]</td>";
}
$rec_table .= "</tr>";
$j++;
$var = $fn[0]. $j;
}
$rec_table .= "</table>";
echo $rec_table;
}
?>


[Non-text portions of this message have been removed]