我在改变方面面临重大问题status
in <select>
通过 jquery-ajax 标记到数据库。
注意:我在 stackoverflow 中搜索了这个问题。但这些答案与我的问题并不接近。这是下面的链接link1 https://stackoverflow.com/questions/34915126/how-to-update-select-boxes-with-php-mysql-jquery-ajax, link2 https://stackoverflow.com/questions/16753613/dynamically-updating-select-boxes-with-php-mysql-aja, link3 https://stackoverflow.com/questions/25894033/changing-the-value-of-a-select-box-with-jquery
When i click on first row select box the data is sent through ajax and the status column in table
get updated and also it is updated in mysql database.
But when is select 2nd, 3rd row it doesn't change not update the status column
in html page nor in database here is the output image.
先感谢您..
Here is the details of my code
database table name: ajaxselect
HTML 文件:index.php
<?php
include('processing.php');
$newobj = new processing();
?>
<html>
<head>
<title>Jquery Ajax select <tag> with PHP Mysql</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
<table border="1">
<tr>
<th>Id</th>
<th>Product name</th>
<th>Status</th>
<th>Action</th>
</tr>
<?php echo $newobj->display();?>
</table>
<script>
$(document).ready(function(){
$("#selectstatus").change(function(){
var statusname = $("#selectstatus").val();
var getid = $("#getid").val();
$.ajax({
type:'POST',
url:'ajaxreceiver.php',
data:{statusname:statusname,getid
:getid},
success:function(result){
$("#display").html(result);
}
});
});
});
</script>
</body>
</html>
Ajax 文件:ajaxreceiver.php
<?php
include('processing.php');
$newobj = new processing();
if(isset($_POST['statusname'],$_POST['getid'])){
$statusid = $_POST['statusname'];
$id = $_POST['getid'];
$newobj->getdata($statusid,$id);
}
?>
PHP 类文件:processing.php
<?php
class processing{
private $link;
function __construct(){
$this->link= new mysqli('localhost','root','','example');
if(mysqli_connect_errno()){
die ("connection failed".mysqli_connect_errno());
}
}
function display(){
$sql = $this->link->stmt_init();
$id=1;
if($sql->prepare("SELECT id,productname,status FROM ajaxselect")){
$sql->bind_result($id,$productname,$status);
if($sql->execute()){
while($sql->fetch()){
?>
<tr>
<td><input type="hidden" id="getid" value="<?php echo $id;?>"><?php echo $id;?></td>
<td><?php echo $productname;?></td>
<td><p id="display"><?php echo $status;?></p></td>
<td>
<select id="selectstatus">
<option>Pending</option>
<option>Delivered</option>
<option>Cancelled</option>
<option>Amount Paid</option>
</select>
</td>
</tr>
<?php
}
}
}
}
function getdata($statusid,$id){
$sql = $this->link->stmt_init();
if($sql->prepare("UPDATE ajaxselect SET status=? WHERE id=?")){
$sql->bind_param('si',$statusid,$id);
if($sql->execute()){
echo $statusid;
}
else
{
echo "Update Failed";
}
}
}
}
?>