脚本宝典收集整理的这篇文章主要介绍了php – 删除行后进入同一数据页面,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
Delete.PHP:
<?PHP require_once ('../include/global.PHP'); $id=$_REQUEST['id']; $sql = "DELETE From appoint WHERE id=".$id; $result=MysqLi_query($con,$sql) or die('Unable to execute query. '. MysqLi_error($con)); if($result){ $sql2 = "SELECT date From appoint WHERE id=".$id; $result2=MysqLi_query($con,$sql2) or die('Unable to execute query. '. MysqLi_error($con)); $rows = MysqLi_fetch_array($con,$result2); header("location:appoint.PHP"); } else { header("location:../update/update_false.PHP"); } ?>@H_502_14@访问getdata.PHP:
<?PHP require_once ('../include/global.PHP'); if($_POST['seldate']) { $selDate = $_POST['seldate']; $sql="SELECT * FROM clinic.appoint WHERE date='$selDate'"; $result = MysqLi_query($con,$sql) or die($sql."<br/><br/>".MysqL_error()); while($rows=MysqLi_fetch_array($result)){ ?> <tr> <td scoPE="row"><?PHP echo $rows['time'] ?></td> <td scope="row"><?PHP echo $rows['name'] ?></td> <td scope="row"><?PHP echo $rows['date'] ?></td> <td scope="row"><form action='/clinic form/appoint/delete.PHP'=<?PHP echo $rows['id']; ?>' method="post"> <input type="hidden" name="id" value="<?PHP echo $rows['id']; ?>"> <input type="submIT" name="submit1" value="Done"> </form> </td> </tr> <?PHP } } ?>@H_502_14@
<script src="https://ajax.GOOGLEapis.COM/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script language="javascript" type="text/javascript"> $(document).ready(function(){ $("#Date").change(function(){ VAR seldate =$(this).val(); $("#scheduleDate").htML(seldate); var dataString = 'seldate='+ seldate; $.ajax({ type: "POST",url: "getdata.PHP",data: dataString,cache: false,success: function(data) { $("#Schedule").html(data); } }); }); }); </script> </head> <body> <div class="container12"> <header> <div align="center"> <div class="column12"> <a href="homepage.PHP"><img src="images/logo.png"/></a> </div> </div> <div align="center"> <div align="center"><a href="logout.PHP">logout</a></div> </div> </header> <h1 id="home">&nbsp;</h1> <div class="alert"></div> <div class="column12" align="left"><B><center>Appointments</B></center><br /> </div> </div> </div> </div> <div class="container12" align="center"> <form action="addApp.PHP" method="post" name="form1" id="form1"> <table width="700px" class="imagetable" align="center"> <th align="center">Name</th> <th>Date</th> <th>Time</th> <th>Contact Number</th> <th>Action</th> <tr> <td><input type="text" name="name" class="large-fld-app" placeholder="name"/></td> <td><input type="text" name="date" class="large-fld-app" placeholder="DD/MM/yyYY"/></td> <td><input type="time" name="time" class="large-fld-app"/></td> <td><input type="text" name="phone" class="large-fld-app"/></td> <td align="center"><input type="submit" value="" name="submit" class="imgClass_save" /> </td> </tr> </table> </form> </div> <?PHP //$sql="SELECT * FROM clinic.appoint"; //$result = MysqLi_query($con,$sql) or die($sql."<br/><br/>".MysqL_error()); //$rows=MysqLi_fetch_array($result) ?> <div class="container"> <table> <thead> <tr> Schedule <th scope="row"> <select name="Date" required class="form-control" id="Date"> <option value="">Please Select Date</option> <?PHP $sql2="SELECT * FROM clinic.appoint group by date"; $result2 = MysqLi_query($con,$sql2) or die($sql2."<br/><br/>".MysqL_error()); while($rows2=MysqLi_fetch_array($result2)){?> <option value="<?PHP echo $rows2['date'] ?>"><?PHP echo $rows2['date'] ?></option> <?PHP } ?> </select> </th> <td class="schedule-offset" colspan="2" id="scheduleDate"></td> </tr> </thead> <tbody id="Schedule"></tbody> </table> </div> </body> </html>@H_502_14@
require_once ('../include/global.PHP'); $id = $_REQUEST['id']; # Find the date for which you are deleting... $query = "SELECT date FROM appoint WHERE id = " . $id; $row = MysqLi_fetch_assoc(MysqLi_query($con,$query)); $request_date = $row['date']; $sql = "DELETE FROM appoint WHERE id=".$id; $result = MysqLi_query($con,$sql) or die('Unable to execute query. '. MysqLi_error($con)); if($result){ header("Location: appoint.PHP?date=" . $request_date); } else { header("Location: ../update/update_false.PHP"); }@H_502_14@现在当你从删除回来时,你有一个$_GET [‘date’].但是当你第一次加载页面时,你没有那个.
$(document).ready(function(){ $("#Date").change(function(){ var seldate =$(this).val(); display_data(seldate); }); // This is the function... function display_data(seldate) { $("#scheduleDate").html(seldate); var dataString = 'seldate='+ seldate; $.ajax({ type: "POST",success: function(data) { $("#Schedule").html(data); } }); } // Now here is the real code for retaining your Date... <?PHP if (!empty($_GET['date'])) { ?> display_data('<?PHP echo $_GET["date"]; ?>') <?PHP } ?> document.getElementById('Date').value = '<?PHP echo @$_GET["date"]; ?>'; });@H_502_14@现在你只需要在dom准备就绪时在特定日期调用display_data()函数.
您还可以使用会话:
示例:在我的PHP代码中,$request_date存储在会话中.
首先,如果尚未启动session_start(),请启动会话.在所有页面中,HTML和DELETE PHP和UPDATE FAIL页面.
$request_date = $row['date']; $_SESSION['date'] = $request_date;@H_502_14@
header("Location: appoint.PHP");@H_502_14@现在改变我的脚本块的这一部分:
从:
<?PHP if (!empty($_GET['date'])) { ?> display_data('<?PHP echo $_GET["date"]; ?>'); <?PHP } ?> document.getElementById('Date').value = '<?PHP echo @$_GET["date"]; ?>';@H_502_14@至:
<?PHP if (!empty($_SESSION['date'])) { ?> display_data('<?PHP echo $_SESSION["date"]; ?>'); <?PHP unset($_SESSION['date']); } ?> document.getElementById('Date').value = '<?PHP echo @$_SESSION["date"]; ?>';@H_502_14@
以上是脚本宝典为你收集整理的php – 删除行后进入同一数据页面全部内容,希望文章能够帮你解决php – 删除行后进入同一数据页面所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。