我开始编程,遇到运动方面的问题,我必须回馈。 该项目的目标是与管理员一起组织一个与PHP相关的网站。 我的问题是,一旦对添加按钮进行了操作,我想向可编辑表中添加空白行。 我的第一个想法是应该在对添加按钮执行的操作的基表中创建一个空行,因此我尝试将按钮连接到SQL查询,但未成功。 然后,我以为我希望将我并排到下一页,将我扔到“添加”按钮上,并且当我编写此行时,她正在将自己保存在数据库中。 也就是说,我已经创建了与Ajax一起使用的功能edit和delete。 如果有人愿意帮助我。 预先谢谢你
<body onload="viewData()">
<div class="container" style="margin-top:35px">
<button id=boutonAdd type="button" class="btn btn-dark">Ajouter</button>
<table id="tabledit" class="table table-bordered table-striped">
<thead>
<tr>
<th scope="col">ID_ATHLETE</th>
<th scope="col">ID_FEDERATION</th>
<th scope="col">NOM_ATHLETE</th>
<th scope="col">SEXE</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.js"></script>
<script src="js/jquery.tabledit.js"></script>
<script>
function viewData(){
$.ajax({
url: 'processAth.php?p=view',
method: 'GET'
}).done(function(data){
$('tbody').html(data)
tableData()
})
}
function tableData(){
$('#tabledit').Tabledit({
url: 'processAth.php',
eventType: 'dblclick',
editButton: true,
deleteButton: true,
hideIdentifier: false,
buttons: {
edit: {
class: 'btn btn-sm btn-warning',
html: '<span class="glyphicon glyphicon-pencil"></span> Editer',
action: 'edit'
},
delete: {
class: 'btn btn-sm btn-danger',
html: '<span class="glyphicon glyphicon-trash"></span> Supprimer',
action: 'delete'
},
save: {
class: 'btn btn-sm btn-success',
html: 'Save'
},
confirm: {
class: 'btn btn-sm btn-danger',
html: 'Confirm'
}
},
columns: {
identifier: [0, 'ID_ATHLETE'],
editable: [[1, 'ID_FEDERATION'],[2, 'NOM_ATHLETE'], [3, 'SEXE']]
},
onSuccess: function(data, textStatus, jqXHR) {
viewData()
},
onFail: function(jqXHR, textStatus, errorThrown) {
console.log('onFail(jqXHR, textStatus, errorThrown)');
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
},
onAjax: function(action, serialize) {
console.log('onAjax(action, serialize)');
console.log(action);
console.log(serialize);
}
});
}
</script>
............................................... ...........................
<?php
$mysqli = new mysqli('localhost', 'root', '', 'grandprix');
if (mysqli_connect_errno()) {
echo json_encode(array('mysqli' => 'Failed to connect to MySQL: ' . mysqli_connect_error()));
exit;
}
$page = isset($_GET['p'])? $_GET['p'] : '' ;
if($page=='view'){
$result = $mysqli->query("SELECT * FROM athlete WHERE deleted != '1'");
while($row = $result->fetch_assoc()){
?>
<tr>
<td><?php echo $row['ID_ATHLETE'] ?></td>
<td><?php echo $row['ID_FEDERATION'] ?></td>
<td><?php echo $row['NOM_ATHLETE'] ?></td>
<td><?php echo $row['SEXE'] ?></td>
</tr>
<?php
}
} else{
// Basic example of PHP script to handle with jQuery-federation plug-in.
// Note that is just an example. Should take precautions such as filtering the input data.
header('Content-Type: application/json; charset="UTF-8"');
$input = filter_input_array(INPUT_POST);
if ($input['action'] == 'edit') {
$mysqli->query("UPDATE athlete SET ID_FEDERATION='". $input['ID_FEDERATION'] . "', NOM_ATHLETE='" . $input['NOM_ATHLETE'] . "'WHERE ID_ATHLETE=". $input['ID_FEDERATION']);
} else if ($input['action'] == 'delete') {
$mysqli->query("UPDATE athlete SET deleted=1 WHERE ID_ATHLETE='" . $input['ID_ATHLETE'] . "'");
} else if ($input['action'] == 'add') {
$mysqli->query('INSERT INTO athlete("ID_FEDERATION","NOM_ATHLETE", "SEXE") VALUES (\' \' \')');
}
mysqli_close($mysqli);
echo json_encode($input);
}
?>