我需要帮助从通过 php 填充并使用 jquery 更新的列表中更新所选项目,这就是我所拥有的:
我的 update.php 前端
<?php include_once('db.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Update Collected</title>
<link rel="stylesheet" href="css/style.css" type="text/css" media="print, projection, screen" />
<link rel="stylesheet" href="css/bootstrap.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/bootstrap-responsive.css" type="text/css" media="screen" />
</head>
<body>
<?php
$sql="SELECT * FROM qrnumber";
$result=mysql_query($sql);
?>
<div class="container-fluid main">
<div class="row-fluid ">
<div class="span12">
<span class="success"></span>
<table cellpadding="0" cellspacing="0" id="tablesorter-demo" class="tablesorter table table-striped">
<thead>
<tr>
<th>id</th><th>Name</th><th>Points</th><th>Collected</th><th>Action</th>
</tr>
</thead>
<?php while($row = mysql_fetch_array($result)) : ?>
<tr id="<?php echo $row['id']; ?>">
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['points']; ?></td>
<td><?php echo $row['total']; ?></td>
<!-- and so on -->
<td>
<input id="total" class="required" type="text" name="total">
<button class="update_btn" rel="<?php echo $row['id']; ?>">update</button>
</td>
</tr>
<?php endwhile; ?>
<?php
// close connection
mysql_close();
?>
</table>
</div>
</div>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.tablesorter.js"></script>
<script>
$(document).ready(function(){
$(function() {
$("#tablesorter-demo").tablesorter({sortList:[[0,0],[2,1]], widgets: ['zebra']});
$("#options").tablesorter({sortList: [[0,0]], headers: {
3:{sorter: false}, 4:{sorter: false}}});
);
$('.update_btn').click(function(){
$('.success').text("loading...");
var id = $(this).attr('rel');
var total = $('#total').val();
$.post('call.php', {Id:id, Total:total}, function(data) {
alert(data);
});
});
});
</script>
</body>
</html>
这是我的 process.php 文件
<?php
include_once('db.php');
var_dump($_POST);
if (isset($_POST['collected'])){
$collected = mysql_real_escape_string(htmlentities($_POST['collected']));
}
$id = $_POST['id'][0];
$total = $_POST['total'];
echo $id. $total;
mysql_query("UPDATE qrnumber SET total='$total'
WHERE id='$id'");
?>
问题是,当我将数字发布到输入字段时,它会连接到我的处理 php 文件,但不会更新内容,它会连接到 db 并将值从 update.php 传递到处理文件(call.php) . 然后,它将所有记录设置为“0”,请有人帮忙。
谢谢,
合资公司