สอนทำเว็บไซต์

AutoRun Next Page

แสดงผลข้อมูลเป็นชุดๆ แบบอัตโนมัติ

autorun_page.php

<!DOCTYPE html> <html lang="en"> <head> <title>Lekjew.com</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css"> <link rel="stylesheet" type="text/css" href="css/dataTables.bootstrap4.css"> <link rel="stylesheet" type="text/css" href="css/responsive.dataTables.css"> <?php include_once("include/style.php"); ?> </head> <body> <?php include_once("include/header.php"); include_once("connectDBMS.php"); ?> <div class="container minbody"> <div class="col-md-12 m-20"><div class="row"> </div></div> <div class="col-md-12 m-20"><div class="row"> <div class="col-md-12"> <div class="table-responsive"> <table id="tableA" class="table table-bordered nowrap" cellspacing="1" border="1" width="100%"> <thead> <tr> <th>ลำดับ</th> <th>ชื่อผู้เข้ารับการรักษา</th> <th>เข้ารักษา</th> <th>เวลา</th> <th>ประเภท</th> <th>คุณหมอ</th> <th>สถานะ</th> </tr> </thead> <tbody id ="showtableA"></tbody> <tfoot> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> </tfoot> </table> </div> </div> <div class="col-md-6"> </div> </div></div> </div> <?php include_once("include/footer.php"); ?> </body> </html> <?php include_once("include/js.php"); sqlsrv_close($ConnDB); ?> <script src="js/jquery.dataTables.js"></script> <script src="js/dataTables.bootstrap4.min.js"></script> <script> RefreshTable(0); CallData(); function CallData(){ var t_datetime = "2024-05-18"; var form_data = new FormData(); form_data.append("t_datetime", t_datetime); $.ajax({ url: "autorun_page_data.php", async: false, cache: false, contentType: false, processData: false, data: form_data, type: 'post', success: function(data) { var tr =""; var JsonData = JSON.parse(data); var resL = JsonData.length; for (var i = 0; i < resL; i++) { tr=tr+"<tr>" ; tr=tr+"<td>"; tr = tr + JsonData[i]["t_no"]; tr=tr+"</td>"; tr=tr+"<td>"; tr = tr + JsonData[i]["t_name"]; tr=tr+"</td>"; tr=tr+"<td>"; tr = tr + JsonData[i]["t_treat"]; tr=tr+"</td>"; tr=tr+"<td>"; tr = tr + JsonData[i]["t_datetime"]; tr=tr+"</td>"; tr=tr+"<td>"; tr = tr + JsonData[i]["t_case"]; tr=tr+"</td>"; tr=tr+"<td>"; tr = tr + JsonData[i]["t_doctor"]; tr=tr+"</td>"; tr=tr+"<td>"; tr = tr + JsonData[i]["t_status"]; tr=tr+"</td>"; tr=tr+"</tr>" ; } $('#showtableA').html(''); $('#tableA').DataTable().destroy(); $('#showtableA').html(tr); RefreshTable(resL); }, error: function(data){ $('#showtableA').html(data); } }); } function RefreshTable(num){ var table = $('#tableA').DataTable( { dom: "<'row'<'col-md-1'<'pull-left'>><'col-md-3'<'pull-left'>><'col-md-8'f><'col-sm-12'tr>>p", searching: false, ordering: false, lengthMenu: [10], scrollY: "550px", scrollCollapse: true, scrollX: true, responsive: true, "pagingType": "full_numbers", "fnInitComplete": function (oSettings) { $('.select_broker_wrapper').find('.tblBroker_head').hide(); } }); $('.dataTables_scrollBody #tableA tr:eq(0) ').empty(); delaytime(num); $('#tableA_paginate').addClass('hide'); } function delaytime(numdata){ var sliced = ""; var timeout = 0; var i = 0; var avgtime = 6000; var delay = 0; var slice = []; var start = 0; var end = 0; var limit = 10; var page = Math.ceil( numdata /limit); $('#allpage').text(page); if(page>0){ for(var i = 1; i<=page; i++){ var start = (i*limit)+1; var end = (end + limit); let timeout = ( avgtime * i); if(i==page){ setInterval( function () { window.location.reload(); } , avgtime*i ); }else{ setInterval( function (){ $('.pagination').removeClass('active'); $('.pagination #tableA_next').click(); var pg = $('.pagination .active .page-link').text(); $('#numpage').text(pg); }, timeout ); } } } } </script>

autorun_page_data.php

<?php include('connectDBMS.php'); $data = array(); $sql = "SELECT t_no, t_name, t_treat, t_datetime, t_case, t_doctor, t_status FROM treat "; if(@$_POST['t_datetime']!="" ){ $sql = $sql ."WHERE convert(nvarchar(10), t_datetime,120) = '".$_POST['t_datetime']."' "; } // echo $sql; $rsc = sqlsrv_query($ConnDB, $sql); while($rowp = sqlsrv_fetch_object($rsc)) { $data[] = array( "t_no" => $rowp->t_no , "t_name" => $rowp->t_name , "t_treat" => $rowp->t_treat , "t_datetime" => $rowp->t_datetime , "t_case" => $rowp->t_case , "t_doctor" => $rowp->t_doctor , "t_status" => $rowp->t_status ); } echo json_encode($data, JSON_UNESCAPED_UNICODE); sqlsrv_close($ConnDB); ?>