如何在hmtl php sql中使数据透视表可编辑

时间:2019-03-20 05:16:54

标签: php html sql

这是我要使其可编辑。我可以在一个简单的表中完成此操作,但是采用这种方法,我很难使该表在其单元格中变得可编辑。我已经搜索了很多次,但仍然没有解决这个问题。希望有人能帮上忙,因为这是我在学术界的论文。 :'(

该表如下所示:

enter image description here

我希望 得分 (“检查”列中的 )变得可编辑,并因此在其sql数据库中进行更新。

这是我的完整代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>VSA System</title><link rel="shortcut icon" href="images/vito.png" type="image/x-icon" />
    <link href="vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">

</head>    
<body>

<div>
<?php

$db = mysqli_connect('localhost', 'root', '', 'deped');
$iddd = 6;    
$iddds = 1;
$idddds = 1;
$idyear = 1;


define('THE_NUMBER', 'SC'); // !important
define('THE_TYPE',     'fullname');         // !imortant
define('SCORE',   'component_value');       // !important    

$query = mysqli_query($db, "SELECT CONCAT(l_name,', ',f_name,' ',m_name) AS fullname, CONCAT(tbl_qa.description,'  /',hps) AS SC, component_value FROM tbl_student, tbl_grade, tbl_qa WHERE tbl_grade.component=3 AND tbl_grade.sub_component=tbl_qa.id AND tbl_student.sid=tbl_grade.stud_id AND tbl_grade.sub_component=tbl_qa.id AND tbl_grade.subject_id=$iddds AND tbl_grade.grading=$idddds AND tbl_grade.year_level=$idyear GROUP BY tbl_grade.hps, fullname ORDER BY tbl_qa.description ASC, tbl_grade.sub_component_number_ex, tbl_grade.hps ASC");

$allType = array();
$sidesql = "SELECT * FROM tbl_student, tbl_grade WHERE tbl_student.section=$iddd GROUP BY tbl_student.sid ORDER BY l_name";
$sidesqls = mysqli_query($db,$sidesql);
$arr = array();
while($rowsss = mysqli_fetch_array($sidesqls)){
    $arr = $rowsss['l_name']. ', ' .$rowsss['f_name']. ' '.$rowsss['m_name'];
        array_push($allType , $arr);
}


$outputNumber = array(); 
$currentInputRow = mysqli_fetch_array($query);

$r_arr = array();

while (isset($currentInputRow[THE_NUMBER])) { 

  $currentNumber = $currentInputRow[THE_NUMBER];

  $theTypeNumber = array();

  foreach ($allType as $type) {
    $theTypeNumber[$type] = '--';
  }

  while ($currentInputRow[THE_NUMBER] == $currentNumber) { 

    $theTypeNumber[$currentInputRow[THE_TYPE]] = $currentInputRow[SCORE];


    $currentInputRow = mysqli_fetch_array($query);
  }

   $currentOutputRowIdx = 0;


   $outputNumber[$currentOutputRowIdx][] = $currentNumber;
   $currentOutputRowIdx++; 



    $item=null;

    $item = explode('/', $currentNumber);


    $score=null;
   foreach ($allType as $outType) {
       $score = $theTypeNumber[$outType];
       if($theTypeNumber[$outType] == '--') {
           $score = 0;
       }


       $r_arr[$currentOutputRowIdx][] = (($score/$item[1])*50+50);

     $outputNumber[$currentOutputRowIdx][] = $theTypeNumber[$outType];
     $currentOutputRowIdx++;
   }

} 




foreach($r_arr as $k => $v) {
    $tt = 0;
    $cnt = 0;
    foreach($v as $k1 => $v2) {
        $cnt++;
        if($v2 == "--") {
            $v2 = 0;
        }
        $tt += $v2;
    }

    array_push($outputNumber[$k], "<b><i>".round($tt/$cnt,2)."</i></b>");
    array_push($outputNumber[$k], "<b><i>".round(($tt/$cnt)*0.20    , 2).'%'."</i></b>");


}

if(count($outputNumber) !=0) {
    array_push($outputNumber[0], "<b>Percentage Score<b>");
    array_push($outputNumber[0], "<b> Weighted Score (20%)<b>");
}




$currentType = -1; 

echo '<table class="table table-bordered table-striped">';
foreach ($outputNumber as $oneOutputRow) {

  echo '<tr>';

  if ($currentType < 0) {
    echo '<td>'. 'Student' .'</td>';
  }
  else {
    echo '<td  style="text-transform:capitalize;">'. $allType[$currentType] .'</td>';
  }

  foreach($oneOutputRow as $column) {
    echo '<td>'. $column .'</td>';
  }
  echo '</tr>';
  $currentType++; 

}
echo '</table>';

?>
</div>
</body>    
</html>    

我非常渴望学习和解决这个问题。请分享您的想法。

1 个答案:

答案 0 :(得分:0)

使用fullDataTable功能项将数据加载和编辑到页面上

DataTable没有内置的编辑选项,

但是您可以通过将其与jEditable jQuery插件连接来实现,如here

所述