I have a form connecting to a db. I'veparsed the form
data into arrays and seperated new entries from edits
to existing entries because of the class file and db
structure. This as written, however, will only work a
for a single record (multiple field) edit. I've stayed
up too long and am beginning to glaze over when I look
at it. Any suggestions? Comments on functionality as
well as elegance are appreciated.
Thanks in advance,
Randall Gremillion
include_once($HTTP_SERVER_VARS['DOCUMENT_ROOT'] .
"/FX/FX.php");
$serverIP = "127.0.0.1";
$vendorID = $_GET["vendorID"];
$repID = $_GET["repID"];
if ($_POST) {
$updateEntries = array(); //stores existing db
entries
$newEntries = array(); //stores new db
entriesbottom.php
$ord = -1;
$recNum = 0;
$newOrd = 0;
foreach ($_POST as $key => $value) {
if ($value != "") {
$lastPartPos = strrchr($key, '_');
$lastPart = substr($lastPartPos, 1);
if (preg_match("/[0-9]+/" , $lastPart)) { //if
it's an existing update
$lastpartnum = strrpos($key, '_');
$firstnum = substr($key, 0, $lastpartnum);
$first = str_replace('_', '.', $firstnum);
//restore periods to field name and strip off record
ID at end
if ($lastPart != $recNum) {
$recNum = $lastPart;
$ord++;
}
$updateEntries[$ord][] = array($recNum, $first,
$value); //populate nested arrays of each entry
} else {
$second = str_replace('_', '.', $key);
//create
array of new entry
$newEntries[$newOrd] = array($second, $value);
//populate nested array of new entry
$newOrd++;
}
}
}
//add to update list
if ($newOrd > 0) {
$Adder = new FX($serverIP);
$Adder->SetDBData("Account_Reports.fp5", "All");
$Adder->AddDBParam("vendorID.calc.txt",
"$vendorID");
for ($k=0; $k < count($newEntries); $k++) {
$Adder->AddDBParam($newEntries[$k][0],
$newEntries[$k][1]);
}
$Added = $Adder->FMNew();
}
}
if (count($updateEntries)>0) {
for ($i=0; $i<count($updateEntries); $i++) {
$b = "Add" . $i;
$c = "Updated" . $i;
$$b = new FX($serverIP);
echo "$b = new FX($serverIP);";
$$b->SetDBData("Account_Reports.fp5", "All");
$boo = $updateEntries[$i][0][0];
$$b->AddDBParam('-recid', $boo);
for ($j=0; $j<count($updateEntries[$i]); $j++) {
$$b->AddDBParam($updateEntries[$i][$j][1],
$updateEntries[$i][$j][2]);
}
$$c = $$b->FMEdit();
}
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php