gpt4 book ai didi

php - 当从表中更新列行时,然后在该列的所有行中提取

转载 作者:行者123 更新时间:2023-11-29 10:31:04 24 4
gpt4 key购买 nike

我做了一个表格,属性代码很少

<table class="table table-hover table-striped">
<thead>
<tr>
<th>Id</th>
<th>File-name</th>
<th>Purpose</th>
<th>Recieved-By </th>
<th>Processed-By</th>
<th>Adress</th>
<th>Contact-No</th>
<th>Date</th>
<th>Update</th>
</tr>`

这里是从数据库表中除更新之外的所有列中获取数据

                  <tbody>
<?php
if ( $search )
{
$p_query = "select * from files where recieved_by like '%$search%' or processed_by like '%$search%' or purpose like '%$search%' or file_name like '%$search%' order by id desc limit $page_start_from, $total_num_page";
}
else
{

$p_query = "select * from files order by id desc limit $page_start_from, $total_num_page";
}
$p_run=mysqli_query($con,$p_query);
if(mysqli_num_rows($p_run)){
while($row=mysqli_fetch_array($p_run))
{
$c_id=$row['id'];
$file=$row['file_name'];
$purpose=$row['purpose'];
$recieve=$row['recieved_by'];
$processed=$row['processed_by'];
$address=$row['address'];
$contact=$row['contact_no'];
$date=$row['date'];
$show_status=$row['show_status'];


?>
<tr>

<td><a href="post.php?post_id=<?php echo $c_id?>"><?php echo $c_id;?></a></td>
<td><a href="post.php?post_id=<?php echo $c_id?>"><?php echo $file;?></a></td>
<td><a href="post.php?post_id=<?php echo $c_id?>"><?php echo $purpose;?></a></td>
<td><a href="post.php?post_id=<?php echo $c_id?>"><?php echo $recieve;?></a></td>
<td><a href="post.php?post_id=<?php echo $c_id?>"><?php echo $processed;?></a></td>
<td><a href="post.php?post_id=<?php echo $c_id?>"><?php echo $address;?></a></td>
<td><a href="post.php?post_id=<?php echo $c_id?>"><?php echo $contact;?></a></td>
<td><a href="post.php?post_id=<?php echo $c_id?>"><?php echo $date;?></a></td>

现在在更新列中,当文件表数据库中的更新列中有值时,更新列中就会发生变化,那么它将在更新列中显示,否则它将打开一个<强> Action 是一个按钮,有一个表单代码在这里

                                                <td>
<?php if( !empty($show_status)){
echo $show_status;
}
else
{
?>
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style=" padding-top: 3px; padding-bottom: 3px;">
Action <span class="caret"></span>
</button>
<ul class="dropdown-menu" style="margin-left:-50px;">
<?php
if(isset($_POST['submit-form']))
{
$update_date=$_POST['reason-date'];
$status=$_POST['reason'];
$p_id=$_POST['idvalue'];
$d_query="INSERT INTO update_table (id, reason, update_date) VALUES ('$p_id', '$status', '$update_date'); update files set show_status =' $status' where id=' $p_id'";
if(mysqli_multi_query($con,$d_query))
{
$msg="file have been submitted ";
header('location:index.php');
}
else
{
$error_msg="Already updated this file";
}


}?>
<script type="text/javascript">
function checkvalue()
{
var ureason=document.forms["sform"]["ureason"].value;
var udate=document.forms["sform"]["udate"].value;
if (ureason=="")
{
alert("Status Field is blank ");
return false;
}
if (udate=="")
{
alert("Date Field is blank ");
return false;
}


}
</script>
<form role="banner" class="actionform" action="index.php" method="POST" name="sform" onsubmit=" return checkvalue()">
<input type="hidden" name="idvalue" value="<?php echo $c_id; ?>">
<label style="font-weight: normal;">Enter Reason*</label><br>
<input type="text" name="reason" placeholder="call or letter or filed " id="ureason"><br>
<label style="font-weight: normal;">Update Date:*</label><br>
<input type="date" name="reason-date" placeholder="enter date here" id="udate">
<br><br>
<input type="submit" name="submit-form" id="actionid" value="Submit" style="background: #3596e0; ">
<?php
if(isset($error_msg))
{
echo "<span style='color:red; margin-bottom:10px;' class='pull-right'>$error_msg</span>";
exit();
}
else if(isset($msg))
{
echo "<span style='color:green;' class='pull-right'>$msg</span>";
exit();
}?>
</form>
</ul>
</div>
<?php
} ?>

</td>
</tr>
<?php
}
}
else {
echo "<h3> NO Related Table is Found Here </h3>";
}
?>
</tbody>
</table>

现在的问题是,当我第一次填写更新操作表单时,它会正常,但是当我要进行第二个或第三个操作时,上面的行更新功能未填充,它不断显示检查表单列是否为空的错误,如何停止这,当我填写一行更新列时,它应该只影响该特定行,请有人帮助我,我在这部分停留了两天。

最佳答案

由于您使用的是INSERT方法,因此请使用UPDATE方法进行更新。

第一次,由于不存在数据,您的 INSERT 方法可以按您想要的方式工作,但之后您必须使用 UPDATE 方法进行更新。

有关更新,请参阅 https://www.w3schools.com/sql/sql_update.asp

对于插入,请参阅 https://www.w3schools.com/sql/sql_insert.asp

关于php - 当从表中更新列行时,然后在该列的所有行中提取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47406004/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com