-4
您好编码器< 3我是一名初学者,在php,mysql的东西,现在我卡在一个地方。我有一个包含批准和拒绝按钮的表,我希望每当我点击批准按钮时,它都会将其状态更改为mysql表中的批准状态。我怎么能做到这一点....通过点击链接如何使用php脚本更改html表中的mysql列表
这里是我的MySQL表
这里是UI
和编码是这样
<?php
// Connect to the database
$dbLink = new mysqli('127.0.0.1', 'root', '', 'hct_db');
if(mysqli_connect_errno()) {
die("MySQL connection failed: ". mysqli_connect_error());
}
// Query for a list of all existing files
$sql = 'SELECT `quote_id`, `name`, `mime`, `size`, `created`, `status` FROM `quote`';
$result = $dbLink->query($sql);
// Check if it was successfull
if($result) {
// Make sure there are some files in there
if($result->num_rows == 0) {
echo '<p>There are no files in the database</p>';
}
else {?>
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th>Quote ID</th>
<th>File Name</th>
<th>File</th>
<th>Size</th>
<th>Created</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead><tbody>
<?php
while($row = $result->fetch_assoc()) {
if ($row["status"]=="Not Approved")
{
echo "<tr>";
echo "<td>" . $row['quote_id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['mime'] . "</td>";
echo "<td>" . $row['size'] . "</td>";
echo "<td>" . $row['created'] . "</td>";
echo '<td><a href="get_file.php?quote_id=' . $row['quote_id'] .'">Download</a></td>';
echo "<td><input type='submit' name='submit' value='Approved'></td>";
echo "<td><input type='submit' name='submit' value='Reject'></td>";
echo "</tr>";
}}
?>
</tbody>
</table>
</div>
</div>
<!-- /.table-responsive -->
<?php
$result->free();
}
// Close the mysql connection
$dbLink->close();}
?>
你需要使用AJAX调用PHP脚本,更改数据库。然后使用javascript将信息更新到客户端,而无需刷新。 – Mattigins 2014-12-09 12:30:46
谢谢@Mattigins,你能给我一些与此相关的链接吗? – AakkiRock 2014-12-09 12:31:52
http://www.w3schools.com/ajax/ – Mattigins 2014-12-09 12:32:18