This is kind of a complicated problem that I can't solve. For starters I have this code:
if (mysql_num_rows($result) > 0) {
for ($j = 0; $j<mysql_num_rows($result); $j++) {
echo "<tr>\n";
for ($k = 0; $k<mysql_num_fields($result); $k++) {
echo "<input type=\"hidden\" name=\"unitnum[]\" value=\"".mysql_result($resultss, $j)."\" READONLY><input type=\"hidden\" name=\"oldvalue[]\" value=\"".mysql_result($result, $j, $k)."\" READONLY><input type=\"hidden\" size=\"6\" name=\"field[]\" value=\"".mysql_field_name($result, $k)."\"><td>".mysql_result($resultss, $j)."</td><td>".mysql_result($resultsss, $j)."<td>".mysql_result($result, $j, $k)."</td><td><input type=\"textfield\" name=\"newvalue[]\" value=\"".mysql_result($result, $j, $k)."\"></td>\n";
//echo "<input type=\"textfield\" size=\"6\" name=\"unitnum[]\" value=\"".mysql_result($resultss, $j, $k)."\" READONLY">;
}
echo "</tr>\n\n";
}
}
The page that posts to this takes all of the fields in the database and allows a user to click multiple checkboxes of the fields that they would like to update the values contained in these fields. The code displays these values and allows a user to edit the values and then submit the form to the page of code that follows:
if(!empty($_POST)){
$newvalue=$_POST['newvalue'];
$oldvalue=$_POST['oldvalue'];
$field=$_POST['field'];
//echo $oldvalue;
//echo "<br>";
//echo "<br>";
//echo $newvalue;
$column=$_POST['column'];
$unitnum=$_POST['unitnum'];
$searchTXT=$_POST['searchTXT'];
$searchColumn=$_POST['searchColumn'];
if(!empty($oldvalue)){
if(!empty($unitnum)){
//$query = "UPDATE master set ";
for($i=0;$i<sizeof($oldvalue);$i++){
if($i == sizeof($oldvalue)-1){
$query2 = "UPDATE master set ";
$query2 .= $field[$i];
$query2 .= " = ";
$query2 .= "'".$newvalue[$i]."'";
$query2 .= " WHERE ";
$query2 .= $field[$i];
$query2 .= " = ";
$query2 .= "'".$oldvalue[$i]."'";
$query2 .= " AND UnitNum = '";
$query2 .= $unitnum[$i]."'";
//$query .= " AND RegionName='$region'";
//mysql_query($query2) or die(mysql_error());
echo "Query is2: $query2<br>";
}
else{
$query1 = "UPDATE master set ";
$query1 .= $field[$i];
$query1 .= " = ";
$query1 .= "'".$newvalue[$i]."'";
$query1 .= " WHERE ";
$query1 .= $field[$i];
$query1 .= " = ";
$query1 .= "'".$oldvalue[$i]."'";
$query1 .= " AND UnitNum = '";
$query1 .= $unitnum[$i]."'";
//$query .= " AND RegionName='$region'";
//mysql_query($query1) or die(mysql_error());
echo "Query is1: $query1<br>";
}
}
}
}
}
My problem is that if someone clicks UnitNum as one of the choices that need to be updated I would like for the program to do all of those updates and then do the updates of all the other checkboxes. This is because I have a where clause that uses the Unitnum. Can anyone help me make this possible??
I greatly appreciate all the help I can get. Thanks in advance!