Greetings, I'm trying to export mysql data to an EXCEL using php,
The problem I have is that when I try to export the data is not exported, that is, it shows the data on the screen again, but it does not give me the window to export ..
<?php $output = ''; if(isset($_POST["export_excel"])) { $sql = "SELECT * from tblaccounts inner join tblinvoiceitems on tblinvoiceitems.invoiceid=tblaccounts.invoiceid WHERE tblaccounts.date BETWEEN '2015-12-25 0:00:00' AND '2016-09-20 23:59:00'"; $result = mysql_query($sql);
$output .= '<table>
<tr>
<th>Transaction Date</th>
<th>Invoice Number</th>
<th>User ID</th>
<th>Company Name</th>
<th>Payment Method</th>
<th>Description (Package or Service)</th>
<th>Amount</th>
<th>Tax</th>
<th>Tax Amount</th>
<th>Total</th>
</tr>';
while ($r2 = mysql_fetch_array($result)){ echo "<tr>"; echo '<td>'.$r2["duedate"].' </td>'; echo '<td>'.$r2["invoiceid"].'</td>'; echo '<td>'.$r2["userid"].'</td>'; $r9 = mysql_fetch_array(mysql_query("SELECT * FROM tblclients WHERE id=$r2[userid]")); echo '<td>'.$r9["companyname"].'</td>'; echo '<td>'.$r2["paymentmethod"].'</td>'; echo '<td>'.$r2["description"].'</td>'; echo '<td>'.$r2["amount"].'</td>'; echo '<td>'.$r2["taxed"].'</td>'; if ($r2["taxed"] == 0 ) { $r3 = mysql_fetch_array(mysql_query("SELECT * FROM tbltax WHERE id = $r2[taxed] ")); echo "<td> no tax </td>"; echo '<td>'.$r2["amount"].'</td>'; } else { $r3 = mysql_fetch_array(mysql_query("SELECT * FROM tbltax WHERE id = $r2[taxed] ")); $r6 = $r2["amount"] / $r3["taxrate"]; $r8 = $r6 + $r2["amount"]; echo "<td> $r6 </td>"; echo "<td> $r8 </td>"; } echo " </tr>"; } $output .= '</table>'; header("Content-Type: application/xls"); header("Content-Disposition: attachment; filename=download.xls"); echo $output; } ?>
Well, the code will get him out of here: link
I modified it a bit because I'm using mysql_query and not mysqli_query ..
Can someone help me?