如何将html表格导出为ex​​cel和分页

我有一个表格,以HTML表格的forms显示mysql数据,每页使用5个logging的分页。 我试图将我的表格导出为ex​​cel,但是它只导出当前显示的行的数据,这意味着如果有20行,它只显示前五个显示的行。 我怎样才能让它出口那些没有被显示,但仍然是search的一部分? 我看到一些其他人有一个类似的问题,但没有答案( 如何将所有的HTML表格行从分页表格导出到Excel文件? )。 希望我能得到一个!

<?php if(isset($_GET['submit']) || isset($_GET['page'])){ // Setting up the Pagination below echo '<center>'; $page_query = "SELECT * FROM tbl_call_log_detail "; $page_query .= "WHERE (dealer_id = '$call_id' AND '$endDate'='1970-01-01' AND '$startDate' ='1970-01-01') OR ( Time <= '$endDate' AND Time >= '$startDate' AND (dealer_id = '$call_id' OR'$call_id'='' )) OR ('$endDate'='1970-01-01' AND '$startDate' ='1970-01-01' AND '$call_id'='') "; $page_result = mysqli_query($conn, $page_query); $total_records = mysqli_num_rows($page_result); $total_pages = ceil($total_records/$record_per_page); $start_loop = $page; $difference = $total_pages - $page; if($difference <= $total_pages){ $start_loop = $total_pages - $difference; } $end_loop = $start_loop + 2; if($end_loop > $total_pages){ $end_loop = $total_pages; } if($difference > $total_pages){ $end_loop = $total_pages; } echo '<div class = "center">'; echo '<div class = "pagination">'; if($page > 1){ echo "<a href= 'dealer_call_log.php?page=1".$urlparameter."'>First</a>"; echo "<a href= 'dealer_call_log.php?page=".($page - 1).$urlparameter."'> << </a>"; } for ($i = $start_loop; $i <= $end_loop; $i++){ echo "<a href= 'dealer_call_log.php?page=".$i.$urlparameter."'>".$i."</a>"; } if($page < $end_loop){ echo "<a href= 'dealer_call_log.php?page=".($page + 1).$urlparameter."'> >> </a>"; echo "<a href= 'dealer_call_log.php?page=".$total_pages.$urlparameter."'>Last</a>"; } if($page < 1){ $page = 1; } echo '</div>'; echo '</div>'; echo '<br>'; $sql = "SELECT Name, SFID, Comment, Time FROM tbl_call_log_detail WHERE (dealer_id = '$call_id' AND '$endDate'='1970-01-01' AND '$startDate' ='1970-01-01') OR ( Time <= '$endDate' AND Time >= '$startDate' AND (dealer_id = '$call_id' OR'$call_id'='' )) OR ('$endDate'='1970-01-01' AND '$startDate' ='1970-01-01' AND '$call_id'='') ORDER BY Time DESC LIMIT $start_from, $record_per_page "; $result = mysqli_query($conn, $sql); $row = mysqli_num_rows($result); $all_property = array(); echo "<table class = 'data-table' border = '1' cellpadding = '9' bgcolor = '#CCCCCC' id = 'data-table'> <tr class = 'data-heading'>"; while($property = mysqli_fetch_field($result)){ echo '<td><b> '. $property ->name. ' </b></td>'; array_push($all_property, $property ->name); } echo '</tr>'; while ($row = mysqli_fetch_array($result)){ echo '<tr>'; foreach($all_property as $item){ echo '<td> '. $row[$item] . ' </td>'; } echo '</tr>'; echo '</center>'; } echo '</table>'; echo '<br>'; ?> // This is what is getting the current rows, but not all <input type = "submit" onclick = "window.open('data:application/vnd.ms-excel, '+encodeURIComponent(document.getElementById('data-table').outerHTML));" value = "Export into excel" /> <?php } ?> 

更新:find我正在寻找的答案我只是运行一个新的SQL查询没有LIMIT子句,并将其存储在一个隐藏的表。 然后我使用隐藏的表来导出数据

 // SQL and hidden table for exporting to excel $page_query2 = "SELECT * FROM tbl_call_log_detail "; $page_query2 .= "WHERE (dealer_id = '$call_id' AND '$endDate'='1970-01-01' AND '$startDate' ='1970-01-01') OR ( Time <= '$endDate' AND Time >= '$startDate' AND (dealer_id = '$call_id' OR'$call_id'='' )) OR ('$endDate'='1970-01-01' AND '$startDate' ='1970-01-01' AND '$call_id'='') ORDER BY TIME DESC "; $page_result2 = mysqli_query($conn, $page_query2); $row2 = mysqli_num_rows($page_result2); $all_property2 = array(); echo "<table class = 'data-table2' border = '1' cellpadding = '9' bgcolor = '#CCCCCC' id = 'data-table2' hidden> <tr class = 'data-heading2'>"; while($property = mysqli_fetch_field($page_result2)){ echo '<td><b> '. $property ->name. ' </b></td>'; array_push($all_property2, $property ->name); } echo '</tr>'; while ($row2 = mysqli_fetch_array($page_result2)){ echo '<tr>'; foreach($all_property2 as $item){ echo '<td> '. $row2[$item] . ' </td>'; } echo '</tr>'; echo '</center>'; } echo '</table>'; ?> <input type = "submit" onclick = "window.open('data:application/vnd.ms-excel, '+encodeURIComponent(document.getElementById('data-table2').outerHTML));" value = "Export into excel" /> <?php } ?> 

您可以使用JQuery table2excel插件以下是链接

 http://www.jqueryscript.net/table/Export-Html-Table-To-Excel-Spreadsheet-using-jQuery-table2excel.html 

尝试下面的代码笔只有JavaScript

 https://codepen.io/kostas-krevatas/pen/mJyBwp