删除档案的部分,首先要先把栏位列印出来
资料表一样参考第23天的文章
https://ithelp.ithome.com.tw/articles/10270360
这次列印的部分会稍长一些
为了把"审核通过"文件的删除按钮给禁止使用,所以把资料表分成两个部份来列印,
原本是想用 if echo 来做,可是因为语法或架构问题,不知该if什麽条件来禁用删除。
<!-- 资料表1阶 显示 审核中、尚未通过 的档案-->
<?php
if(isset($_SESSION['auth']))
{
$idd = $_SESSION['auth_user']['user_id'];
//搜寻 符合你帐号,且非"审核通过"的文件
//下面 ORDER BY 是排序而已
$query = "SELECT * FROM document WHERE id = '$idd' AND doc_pass !='1'
ORDER BY doc_pass DESC, doc_type ASC,doc_id DESC ";
}
$query_run = mysqli_query($con,$query);
?>
<!-- 资料表2阶 -->
<?php
if(isset($_SESSION['auth']))
{
$iddZ = $_SESSION['auth_user']['user_id'];
//搜寻 符合你帐号,且是"审核通过"的文件,且之後删除栏位那边不列印按钮
$queryZ = "SELECT * FROM document WHERE id = '$iddZ' AND doc_pass ='1'
ORDER BY doc_type ASC, doc_id DESC";
}
$query_runZ = mysqli_query($con,$queryZ);
?>
<!---档案列表 1阶--------------------------->
<table class="table table-sm table-bordered"style="text-align:center;">
<thead style="text-align:center;">
<tr style="text-align:center;">
<th>档案类别</th>
<th>档案预览</th>
<th>审核备注</th>
<th>文件状态</th>
<th>删除</th>
</tr>
</thead>
<tbody>
<?php
if(mysqli_num_rows($query_run) > 0)
{
$DE = $_SESSION['auth_user']['user_id'];
foreach($query_run as $row)
{
?>
<tr>
<td style=";"><?php echo $row['doc_type']; ?></td>
<td style="max-width: 190px; font-size: 17px;">
<a href="index2.php?downl_file=<?php echo $row['stu_img'] ?>">
<?php echo $row['stu_img']; ?>
</a><br>
<?php echo $row['doc_date']; ?>
</td>
<td style="max-width: 200px;width: 200px">
<sub><?php echo $row['tea_mark']; ?></sub>
</td>
<td>
<?php
if($row['doc_pass'] =='1')
{
echo '<font color="BLUE" style="font-weight:bold;">通过</font>';
}
elseif($row['doc_pass'] =='0')
{
echo '<font color="RED" style="font-weight:bold;">不通过</font>';
}
else
{
echo '<font color="GRAY" style="font-weight:bold;">
审核中
</font>';
}
?>
</td>
<td>
<form method="POST">
<input type="hidden" name="delete_id" value="<?php echo $row['doc_id']; ?>">
<input type="hidden" name="del_stu_img" value="<?php echo $row['stu_img']; ?>">
<button id="delete_btn"type="submit" name="delete_stu_img"
class="badge badge-danger"
onclick="javascript:return del();">
删除
</button>
</form>
</td>
</tr>
<?php
}
}
else
{
}
?>
</tbody>
<!---档案列表 2阶--------------------------->
<tbody>
<?php
if(mysqli_num_rows($query_runZ) > 0)
{
foreach($query_runZ as $rowZ)
{
?>
<tr>
<td style=" opacity: 0.7;"><?php echo $rowZ['doc_type']; ?></td>
<td style=" opacity: 0.7;max-width: 190px;">
<a href="index2.php?downl_file=<?php echo $rowZ['stu_img'] ?>">
<?php echo $rowZ['stu_img']; ?>
</a><br>
<?php echo $rowZ['doc_date']; ?>
</td>
<td style="max-width: 200px;width: 200px;opacity: 0.6;">
<sub><?php echo $rowZ['tea_mark']; ?></sub>
</td>
<td>
<?php
if($rowZ['doc_pass'] =='1')
{
echo '<font color="BLUE" style="font-weight:bold;">通过</font>';
}
elseif($rowZ['doc_pass'] =='0')
{
echo '<font color="RED" style="font-weight:bold;">不通过</font>';
}
else
{
echo '<font color="GRAY" style="font-weight:bold;">
审核中...
</font>';
}
?>
</td>
<td style=" opacity: 0.7;">
--
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
再来是删除档案的php (主要是下面的 unlink执行删除,其余是为了判断删除哪个)
<?php
/*删除档案...*/
if (isset($_POST['delete_stu_img']))
{
$id = $_POST['delete_id'];
$stu_img = $_POST['del_stu_img'];
$query = "DELETE FROM document WHERE doc_id='$id' ";
$query_run = mysqli_query($con,$query);
if($query_run)
{
unlink("uploads/$DE/".$stu_img);
$_SESSION['status'] ="档案删除成功!";
setcookie("COOK01","", time()-1200);
header('Location: index2.php');
}
else
{
$_SESSION['status'] ="档案删除失败!";
header('Location: index2.php');
}
}
?>
因为很少写程序,当初为了禁用删除按钮的判断,就想了好久,最後是用很暴力的方法来解(不同搜寻条件)...
今天就先这样,下次见。
>>: Day 26. Hashicorp Vault: Rate Limit
对於资料库管理员而言, 另一项重要任务是异质平台之间的资料沟通. 接下来实作从SQL到NSQL的资料...
更改 state 有其风险,State manipulation 有赚有赔,更改前应详阅官方文件说明...
今天在赌场中有听到某位赌徒问了一位老师问题,是关於庄家吃货的策略 简单来说就是根据买卖明细判断,当某...
Internet金钥交换(IKE)是IPsec的关键体系结构组件。 它用於执行相互身份验证以及建立...
学习率(learning rate) 学习率为控制模型中梯度下降的速度,也有人称为步长。 公式:新权...