How to Transfer your Data in Database to Excel in PHP/MySQL

If you are looking for on how to Transfer your Data in Database to Excel then you are at the right place. This PHP Excel tutorial the user enables to make a backup copy of your data in your database in the form of excel worksheet. Kindly click the button to save the excel file to your computer. Creating a table with your data from the database and one button to download the data and save it as excel file as shown in the image below. ResultHere's the source code in the image above.
  1. <div class="alert alert-info">
  2. <button type="button" class="close" data-dismiss="alert">&times;</button>
  3. <strong>Excel Writer</strong>&nbsp;Click The Button to View th e Excel File
  4. </div>
  5.  
  6. <?php
  7.  
  8. $excel = mysql_query("select * from member")or die(mysql_error());
  9. $row = mysql_fetch_array($excel);
  10. $member_excel_id = $row['member_id'];
  11. ?>
  12.  
  13. <form method="POST" action="excel.php">
  14. <input type="hidden" name="id_excel" value="<?php echo $member_excel_id; ?>">
  15. <button id="save_voter" class="btn btn-primary" name="save"> Download Excel File </button>
  16. </form>
  17.  
  18. <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
  19.  
  20.  
  21. <tr>
  22. <th>FirstName</th>
  23. <th>LastName</th>
  24. <th>MiddleName</th>
  25. <th>Address</th>
  26. <th>Email</th>
  27. </tr>
  28. </thead>
  29. <?php
  30. $query = mysql_query("select * from member") or die(mysql_error());
  31. while ($row = mysql_fetch_array($query)) {
  32. ?>
  33. <tr>
  34. <td><?php echo $row['firstname']; ?></td>
  35. <td><?php echo $row['lastname']; ?></td>
  36. <td><?php echo $row['middlename']; ?></td>
  37. <td><?php echo $row['address']; ?></td>
  38. <td><?php echo $row['email']; ?></td>
  39. </tr>
  40.  
  41.  
  42. </tbody>
For more question about this source code just email me at [email protected] or comment in this tutorial. Hope that this tutorial will help you a lot.

Thank you

Add new comment