All pastes #766103 Raw Edit

Someone

public php v1 · immutable
·published 2007-11-08 16:54 UTC
rendered paste body
// submissionif (isset($_POST['submit2'])){  $rows     = $_POST['rows'];  $shifts   = array(3,1,2);  // set the timestamp to be midnight today so data will always be between startDate and endDat  $year   = strftime("%Y", $startDate);  $month  = strftime("%m", $startDate);  $day    = strftime("%d", $startDate);  $date  = mktime(24, 0, 0, $month, $day, $year);    // populate columns  $columns  = array();  array_push($columns, "date", "group");  for ($i=0; $i<count($shifts); $i++)  {    $shift = $shifts[$i];    array_push($columns, "mil$shift", "meters$shift", "product$shift", "wasteProd$shift", "wastePer$shift", "eff$shift");  }  array_push($columns, "line", "avgLine", "wasteTotal",  "wasteProd3",  "wastePercent",  "avgEff");    // populate values  $values   = array();  for ($i=0; $i<$rows; $i++)  {    $rows2  = $_POST['subRows'.$i];    $group  = $_POST['group'.$i];    for ($j=0; $j<$rows2; $j++)    {      $rowValues = array($date, $group);      for ($k=0; $k<count($shifts); $k++)      {        $shift      = $shifts[$k];                        $mil        = $_POST['mil'.$shift.'_'.$i.'_'.$j];        $meters     = $_POST['meters'.$shift.'_'.$i.'_'.$j];        $product    = $_POST['product'.$shift.'_'.$i.'_'.$j];        $wasteProd  = $_POST['wasteProd'.$shift.'_'.$i.'_'.$j];        $wastePer   = $_POST['wastePer'.$shift.'_'.$i.'_'.$j];        $eff        = $_POST['eff'.$shift.'_'.$i.'_'.$j];                array_push($rowValues, "$mil", "$meters", "$product", "$wasteProd", "$wastePer", "$eff");      }      $line         = $_POST['line_'.$i.'_'.$j];      $avgLine      = $_POST['avgLine_'.$i.'_'.$j];      $wasteTotal   = $_POST['wasteTotal_'.$i.'_'.$j];      $wastePercent = $_POST['wastePercent_'.$i.'_'.$j];      $avgEff       = $_POST['avgEff_'.$i.'_'.$j];            array_push($rowValues, "$line", "$avgLine", "$wasteTotal", "$wastePercent", "$avgEff");      array_push($values, $rowValues);    }  }    // INSERT INTO table_name VALUES (value1, value2,....)  if ($stage == "new")  {    for ($i=0; $i<count($values); $i++)    {      $sql = "INSERT INTO mpsr VALUES (";      for ($j=0; $j<count($values[$i]); $j++)      {        $sql .= "'".$values[$i][$j]."'";        if ($j != count($values[$i])-1) $sql .= ",";      }      $sql .= ")";      echo "$sql<br>";    }  }  // UPDATE table_name SET column_name = new_value, column_name2 = new_value2,.... WHERE column_name = some_value  elseif ($stage == "edit")  {    for ($i=0; $i<count($values); $i++)    {      $sql = "UPDATE mpsr SET ";      for ($j=0; $j<count($values[$i]); $j++)      {        $sql .= "$columns[$j] = '".$values[$i][$j]."'";        if ($j != count($values[$i])-1) $sql .= ",";      }      $sql .= "WHERE column_name = something (need to incorporate autoincreasing id)";      echo "$sql<br>";    }  }  }