Search
 
SCRIPT & CODE EXAMPLE
 

PHP

export mysql data to word in php

<?php 
include ("dbConnect.php");

function databaseOutput() {

  $dbQuery = $db->prepare("select * from student");
  $dbQuery->execute();

  while ($dbRow = $dbQuery->fetch(PDO::FETCH_ASSOC)) {
?>
    <tr>
      <td><?php echo $dbRow['ID']; ?></td>
      <td><?php echo $dbRow['Forename']; ?></td>
      <td><?php echo $dbRow['Surname']; ?></td>
      <td><?php echo $dbRow['Email']; ?></td>
      <td><?php echo $dbRow['B_number']; ?></td>
      <td><?php echo $dbRow['School']; ?></td>
      <td><?php echo $dbRow['Campus']; ?></td>
      <td><?php echo $dbRow['Research_Institute']; ?></td>
      <td><?php echo $dbRow['FTPT']; ?></td>
    </tr>
<?php    

  }

} // end of function databaseOutput()

if ($_POST['submit_docs']) { // word output

  header("Content-Type:application/msword");
  header("Expires: 0");
  header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  header("content-disposition: attachment;filename=test.docx");

?>
<html>
  <body>
    <h1>Students</h1>
    <table>
      <tr>
        <th>ID</th><th>Forename</th><th>Surname</th><th>Email</th><th>B Number</th><th>School</th><th>Campus</th><th>Research Institute</th><th>FT/PT</th>
      </tr>
      <?php databaseOutput(); ?>
    </table>
  </body>
</html>
<?php

  exit; // end of word output

}
?>
<html>
  <head>
    <title>Students</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet"   href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://dunluce.infc.ulst.ac.uk/cw11ba/project/Project/mycss.css">
  </head>
  <body>
    <form name="export_form" action="<?php echo($_SERVER['PHP_SELF']);?>" method="post">
      <input type="submit" name="submit_docs" value="Export as MS Word" class="input-button" /> <a href="https://dunluce.infc.ulst.ac.uk/cw11ba/project/Project/admin.php"><button type="button" class= "btn btn-block">Go back to Admin Area</button></a>
    </form>
    <table class="table table-striped" id="student">
      <tr>
        <th>ID</th><th>Forename</th><th>Surname</th><th>Email</th><th>B Number</th><th>School</th><th>Campus</th><th>Research Institute</th><th>FT/PT</th>
      </tr>
      <?php databaseOutput(); ?>
    </table>
  </body>
</html>
Comment

PREVIOUS NEXT
Code Example
Php :: cmd disable wifi driver 
Php :: html pagination php 
Php :: update query laravel 
Php :: How do I change the URL of Add to cart in WooCommerce 
Php :: laravel where 2 column 
Php :: php pdo setting error modes 
Php :: wordpress enable post thumbnail 
Php :: mysql Cannot pass parameter 2 by reference 
Php :: laravel simplexmlelement not found 
Php :: get all users created in a month laravel 
Php :: wordpress use jquery in plugin 
Php :: get id from current url for php 
Php :: convert php array to javascript json laravel 
Php :: php pdo error 500 
Php :: get return value from another function laravel 
Php :: wordpress add button to admin bar 
Php :: php array serialize 
Php :: woocommerce get shipping classes 
Php :: php get first element of iterator class 
Php :: php apns notification source code 
Php :: active page in laravel 
Php :: laravel controller constructor auth user null 
Php :: php <= 
Php :: wordpress get post date custom format 
Php :: object oriented programming php 
Php :: get_the_terms 
Php :: php inline if condition date time 
Php :: laravel collection to array 
Php :: php max int 
Php :: insert array values in database using codeigniter 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =