I am using one form which has 50+ fields . I am done with insert, select and delete of the record but I am confused with update record because If user is updating one or two fields out of 50 then update query should be with minimal fields. but how can I detect that onlt this fields are edited and this fields needs to update on server side? somebody please help me with precise solution.
Asked
Active
Viewed 92 times
0
-
"If user is updating one or two fields out of 50 then update query should be with minimal fields" — Why? – Quentin Mar 20 '17 at 15:01
-
Show us what you tried so far – Gangadhar Jannu Mar 20 '17 at 15:13
-
Update statements generally aren't that taxing. Although you pose an interesting question, you shouldn't worry about building the statement dynamically from what has been updated or not. Mainly depends on type of DB (SQL or NoSQL) – DDelgro Mar 20 '17 at 15:55
1 Answers
1
To get a precise solution would require more data (in my opinion); however, I believe what you are asking can accomplished with PHP by building your update statement through the use of a variable and iterating through the $_POST data (be advised this is untested).
//assumes control names on form = field names in db
$strSQL = "UPDATE tblWhatever SET ";
$fieldsAndvalues = "";
$markers = "";
foreach($_POST as $key => $value)
{
if ($value <> "") {
//code to check for $value's data type and set $marker to what is
//appropriate (e.g., string set $markers to "'", if numeric set to "", etc.)
$fieldsAndvalues .= $key . "=" . $marker . $value . $marker . ","
}
}
//Remove final comma (,), build final SQL statment, execute statement
if ($fieldsAndvalues <> "") {
$strSQL .= substr($fieldsAndvalues,0,-1) . " WHERE <whatever criteria is used>";
//execute query with whatever error checking and such you require
}

billyhoes
- 346
- 1
- 9