我有一个PHP页面,显示待处理的声明,当选中复选框并更新阵列时,可以更改其状态。
<?php include("partials/header.php"); ?>
<p>Manage expenses here!</p>
<body>
<style type="text/css">
#dis{
display:none;
}
</style>
<div id="dis">
<!-- here message will be displayed -->
</div>
<p>Current Claims</p>
<div class="container">
<form method="post" action="export.php" enctype="multipart/form-data" >
<table cellspacing="0" width="100%" id="example" class="table table-striped table-hover table-responsive">
<thead>
<tr>
<th>ID</th>
<th>Employee ID</th>
<th>Ref</th>
<th>Date</th>
<th>Filed Date</th>
<th>Type</th>
<th>Client</th>
<th>Project</th>
<th>Narrative</th>
<th>Net</th>
<th>VAT</th>
<th>Status</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
//connection details
require_once 'dbconfig.php';
//end connection details
$query = "SELECT * FROM claim WHERE status='pending'";
$result = mysql_query($query);
if($result === false) {
die(mysql_error());
}
while($row = mysql_fetch_array($result)){
$row_id = $row['c_id'];
$employee_id = $row['employee_id'];
$claim_ref = $row['claim_ref'];
$transaction_date = $row['transaction_date'];
$filed_date = $row['filed_date'];
$expense_type_id = $row['expense_type_id'];
$client_code_id = $row['client_code_id'];
$project_code_id = $row['project_code_id'];
$narrative = $row['narrative'];
$net = $row['net'];
$vat = $row['vat'];
$status = $row['status'];
echo
"<tr>
<td>" . $row_id . "</td>
<td>" . $employee_id . "</td>
<td>" . $claim_ref . "</td>
<td>" . $transaction_date . "</td>
<td>" . $filed_date . "</td>
<td>" . $expense_type_id . "</td>
<td>" . $client_code_id . "</td>
<td>" . $project_code_id . "</td>
<td>" . $narrative . "</td>
<td>" . $net . "</td>
<td>" . $vat . "</td>
<td>" . $status . "</td>
<td><input type='checkbox' name='c_id[]' value='" . $row_id . "'/></td>
</tr>";
}
echo "</tbody></table><input type='submit' value='accept'></form>"; //end form
/***** Update Status *****/
/*print_r($_POST);*/
if(gettype($_POST['c_id'])=="array"){
foreach($_POST['c_id'] as $val){
$id_c = $val;
$query2 = "UPDATE claim SET status = 'accepted' where c_id='".$id_c."'";
$result2 = mysql_query($query2);
if($result2 === false) {
die(mysql_error());
}
echo "Status " .$id_c. " is updated. <br>";
}
}
mysql_close();
?>
</tbody>
</table>
</div>
</div>
<br />
</script>
</body>
</html>
Q1。我想知道将状态列更改为接受的行是否也可以以某种方式导出到csv文件。
Q2。有没有办法有两个按钮,一个用于接受,另一个用于拒绝,因为每个索赔都有三种可能的状态:待定,接受,拒绝
更新:声明表如下:http://sqlfiddle.com/#!9/5ce91
create table claim (
c_id INT(5) zerofill primary key auto_increment,
claim_ref VARCHAR(7),
employee_id integer NOT NULL REFERENCES employee(emp_id),
transaction_date DATE,
filed_date DATE,
expense_type_id VARCHAR(20) REFERENCES expense_type(expense_type),
client_code_id VARCHAR(7) REFERENCES client(client_code),
project_code_id VARCHAR(10) REFERENCES project(project_code),
narrative VARCHAR(255),
net decimal(6,2),
vat decimal(6,2),
status ENUM('pending', 'rejected', 'accepted'))
ENGINE = InnoDB;
另一点是该项目在大约一周后结束,所以我宁愿不更新到PDO或MySQLi,尽管如果有人在其中一个中有一个完整的解决方案它会同样好,谢谢。