在search引擎上添加“下载到Excel”button

我想在网站上添加一个“下载到Excel”button。

我已经build立了一个使用PHP和MySQL的search引擎。

当我search一个关键字时出现一个表,我希望这个表是

我已经尝试过在这个网站上的解决scheme,但数据不会在正确的单元格! 谢谢你的帮助!!

<?php $dbhost = 'xxx'; $username = 'xxx'; $password = 'xxx'; mysql_connect("$dbhost" , "$username", "$password" ); mysql_select_db("Data") or die("could not find the database!"); $output = ''; if(isset($_GET['search'])) { $searchkey = $_GET['search']; $query = mysql_query("SELECT * FROM Linkedin WHERE email LIKE '%$searchkey%' ") or die("Could not search"); $count = mysql_num_rows($query); if ($count == 0) { $output = 'There was no search results !' ; } else { echo '<table class="table table-striped table-bordered table-hover">'; echo "<tr><th>Email</th><th>Hashkey</th><th>Breached account</th></tr>"; while ($row = mysql_fetch_array($query)) { $email = preg_replace('/(' . $searchkey . ')/i', '<mark>\1</mark>', $row["email"]); $hashkey = $row['hashkey']; echo "<tr><td>"; echo $email; echo "</td><td>"; echo $hashkey; echo "</td><td>"; echo "Linkedin"; echo "</td></tr>"; $output = '</table>'; } echo '<div>'."$count results were found for '$searchkey'.".'</div>'.'</br>'; } echo $output; } ?> 

使用jQuery数据expression的目的。 这是容易和优雅。 https://datatables.net/extensions/buttons/examples/initialisation/export