Answer the question
In order to leave comments, you need to log in
How to upload data to execl or csv?
I'm trying to export data from my database to an excel file (in execl or csv),
but I have problems with the export, the data is not loaded in csv.
https://4kpornindex.com/
php code
<?php
$connect = new PDO('mysql:host=localhost;dbname=123', '123', 'invoice123');
$query ="SELECT * from tbl_order";
$result = mysqli_query($connect, $query);
?>
<form method="post" action="export.php" align="center">
<input type="submit" name="export" value="CSV Export" class="btn btn-success" />
</form>
<table id="data-table" class="table table-bordered table-striped">
<thead>
<tr style="background-color: cornflowerblue;">
<th>Invoice No.</th>
<th>Invoice Date</th>
<th>Student Name</th>
<th>Total Amount</th>
<th>Total Amount</th>
<th>Total Amount</th>
<th>Total Amount</th>
<th>Total Amount</th>
<th>Total Amount</th>
<th>Total Amount</th>
</tr>
</thead>
<?php
while($row = mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row["order_id"]; ?></td>
<td><?php echo $row["order_no"]; ?></td>
<td><?php echo $row["order_date"]; ?></td>
<td><?php echo $row["order_receiver_name"]; ?></td>
<td><?php echo $row["order_total_before_tax"]; ?></td>
<td><?php echo $row["order_total_tax1"]; ?></td>
<td><?php echo $row["order_total_tax2"]; ?></td>
<td><?php echo $row["order_total_tax"]; ?></td>
<td><?php echo $row["order_total_after_tax"]; ?></td>
<td><?php echo $row["order_datetime"]; ?></td>
</tr>
<?php
}
?>
</table>
</div>
<br>
<?php
//export.php
if(isset($_POST["export"]))
{
$connect = new PDO('mysql:host=localhost;dbname=123', '123', 'invoice123');
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
$output = fopen("php://output", "w");
fputcsv($output, array('
Invoice No.', 'Invoice Date', 'Student Name', 'Total Amount'));
$query = "SELECT * from tbl_order";
$result = mysqli_query($connect, $query);
while($row = mysqli_fetch_assoc($result))
{
fputcsv($output, $row);
}
fclose($output);
}
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question