Это таблица, которую я хотел сделать редактируемой. Я могу сделать это в простой таблице, но с таким подходом мне трудно сделать эту таблицу редактируемой в своей ячейке. Я искал его так много раз, но я до сих пор не могу решить эту проблему.
Таблица выглядит так:
Я хочу, чтобы баллы (в столбце EXAM) стали редактируемыми и обновленными в своей базе данных 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>






Используйте функциональные возможности fullDataTable для загрузки и редактирования данных на странице.
DataTable не имеет встроенных опций редактирования,
но вы можете сделать это, подключив его с плагином jEditable jQuery, как описано здесь