1

いつも質問すみません!!データベースからのデータのレコードを表示するテーブルがあります。生活を楽にするために、jquery を使用して編集可能にして、ユーザーが別のページにリダイレクトすることなく、領域を右クリックしてすぐに編集できるようにしました。いくつかの質問..チェックボックスとリンクのあるテーブルの領域がクリックされたときに応答しない/編集できないように、以下のコードを改良するにはどうすればよいですか? また、現時点では編集機能が完全に機能しておらず、問題がどこにあるかを把握するのに問題があります。テーブルは、以下の jquery で定義されたすべてに応答しますが、データベースを更新しません。

私のjqueryコードedit.jsがあります

$(function() {
$('tbody').on('click','td',function() {
displayForm( $(this) );
});

});

function displayForm( cell ) {

var column = cell.attr('class'),
id = cell.closest('tr').attr('id'),
cellWidth = cell.css('width'),
prevContent = cell.text()

form = '<form action="javascript: this.preventDefault"><input type="text" name="newValue" value="'+prevContent+'" /><input type="hidden" name="id" value="'+id+'" />'+'<input type="hidden" name="column" value="'+column+'" /></form>';

cell.html(form).find('input[type=text]')
.focus()
.css('width',cellWidth);

cell.on('click', function(){return false});

cell.on('keydown',function(e) {
if (e.keyCode == 13) {//13 == enter
changeField(cell, prevContent);//update field
} else if (e.keyCode == 27) {//27 == escape
cell.text(prevContent);//revert to original value
cell.off('click'); //reactivate editing
}
});

}

function changeField( cell, prevContent ) {

cell.off('keydown');
var url = 'edit.php?edit&',
input = cell.find('form').serialize();

$.getJSON(url+input, function(data) {
if (data.success)
cell.html(data.value);
else {
alert("There was a problem updating the data.  Please try again.");
cell.html(prevContent);
}

});
cell.off('click');
}

そして私のedit.phpには次のものがあります:

<?php
include ("common.php");

if (isset($_GET['edit'])){
$column = $_GET['column'];
$id = $_GET['id'];
$newValue = $_GET["newValue"];

$sql = 'UPDATE compliance_requirement SET $column = :value WHERE ComplianceID = :id';
$stmt = $dbh ->prepare($sql);
$stmt->bindParam(':value', $newValue);
$stmt->bindParam(':id', $id);
$response['success'] = $stmt->execute();
$response['value']=$newValue;

echo json_encode($response);
}?>

そして最後に私のhtml..

<div class="compTable">
<table>
<thead><tr><th>Compliance Name</th><th>Compliance Goal</th><th>Compliance  Description</th><th>Opions</th><th>Invite</th></tr></thead>

<tbody>
<?php
$sql = 'SELECT * FROM compliance_requirement';
$results = $db->query($sql);
$rows = $results->fetchAll();

foreach ($rows as $row) {
echo '<tr id="'.$row['ComplianceID'].'">';
echo '<td class="crsDesc">'.$row['ComplianceName'].'</td>
<td >'.$row['ComplianceGoal'].'</td> 
<td >'.$row['ComplianceDescription'].'</td>
<td ><a href =inviteObstacle.php?action=invite&id=name1> InviteObstacle </a></td>
<td style="text-align: center; vertical-align: middle;"> <input type="checkbox" name="query_myTextEditBox">
</td>';
echo '</tr>';
}?>
</tbody>
</table>
</div>

あなたの助けに感謝します。前もって感謝します

4

1 に答える 1