Hello all!
i have here a code that will display record from my DB. I would like to ask for help on how will i export the displayed record to excel?
here is my code:
<html>
<head>
<title>Export to Excel</title>
</head>
<body>
<form action="saverec.php" method="post">
<?php
define ('DB_NAME', 'try1');
define ('DB_USER', 'root');
define ('DB_PASSWORD', '');
define ('DB_HOST', 'localhost');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if (!$db_selected) {
die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
}
$strSQL = "SELECT * FROM record ORDER BY lname";
$rs = mysql_query($strSQL);
?>
<table border="1">
<tr>
<th>Name: </th>
</tr>
<tr>
<th>Practice: </th>
</tr>
<tr>
<th>Project Name: </th>
</tr>
<tr>
<th>Employee Name</th><th>Time Message sent</th><th>Time Replied</th><th>On leave?</th><th>Comments</th>
</tr>
<?php
while($row = mysql_fetch_array($rs)) {
?>
<tr>
<td><?php echo $row['lname'] . ", " . $row['fname'] ?></td><td><?php echo $row['hour1'] . ": " . $row['min1'] . " " . $row['ampm'] ?></td>
<td><?php echo $row['hour2'] . ": " . $row['min2'] . " " . $row['ampm1'] ?></td><td><?php echo $row['leave'] ?></td><td><?php echo $row['comment'] ?></td>
</tr>
<?php
}
?>
</table>
<table>
<tr>
<th>Sending failed</th>
<td>
<?php echo $row['sf'] ?>
</td>
<th>Receiving failed</th>
<td>
<?php echo $row['rf'] ?>
</td>
<th>Total</th>
<td>
<?php echo $row['total'] ?>
</td>
<th>Sending percentage</th>
<td>
<?php echo $row['sp'] ?>
</td>
<th>Receiving percentage</th>
<td>
<?php echo $row['rp'] ?>
</td>
</tr>
</table>
<?php mysql_close(); ?>
<input type="submit" name="Submit" value="Save" >
</form>
</body>
</html>
Thanks! :)