14-12-17, 09:48 PM
(آخر تعديل لهذه المشاركة : 15-12-17, 05:47 PM {2} بواسطة طالب برمجة.)
هذا تعديل لعله يفيد
ملف csvexport.php
ملف txtexport.php
هذا رابط لتجربة التعديل
http://csvexport.000webhostapp.com
PHP كود :
<?php
$connect = mysqli_connect("localhost", "AA", "2", "AAS");
$query ="SELECT * FROM log ORDER BY timek desc";
$result = mysqli_query($connect, $query);
?>
<!DOCTYPE html>
<html>
<head>
<title>Webslesson Tutorial | Export Mysql Table Data to TXT file in PHP</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<br /><br />
<div class="container" style="width:900px;">
<h2 align="center">Export Mysql Table Data to CSV or TXT file in PHP</h2>
<h3 align="center">Employee Data</h3>
<br />
<form method="post" action="csvexport.php" align="center">
<input type="submit" name="export" value="CSV Export" class="btn btn-success" />
</form>
</br>
<form method="post" action="txtexport.php" align="center">
<input type="submit" name="export" value="TXT Export" class="btn btn-success" />
</form>
<br />
<div class="table-responsive" id="employee_table">
<table class="table table-bordered">
<tr>
<th width="5%">Qso_id</th>
<th width="5%">CALLop</th>
<th width="5%">qso_date</th>
<th width="5%">timek</th>
<th width="5%">bands</th>
</tr>
<?php
while($row = mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row["Qso_id"]; ?></td>
<td><?php echo $row["CALLop"]; ?></td>
<td><?php echo $row["qso_date"]; ?></td>
<td><?php echo $row["timek"]; ?></td>
<td><?php echo $row["bands"]; ?></td>
</tr>
<?php
}
?>
</table>
</div>
</div>
</body>
</html>
ملف csvexport.php
PHP كود :
<?php
//csvexport.php
if(isset($_POST["export"]))
{
$connect = mysqli_connect("localhost", "AA", "2", "AAS");
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
$output = fopen("php://output", "w");
fputcsv($output, array('Qso_id', 'CALLop', 'qso_date', 'timek', 'bands'));
$query ="SELECT * FROM log ORDER BY timek desc";
$result = mysqli_query($connect, $query);
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{
fputcsv($output, $row);
}
fclose($output);
}
?>ملف txtexport.php
PHP كود :
<?php
//txtexport.php
if(isset($_POST["export"]))
{
$connect = mysqli_connect("localhost", "AA", "2", "AAS");
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.txt');
$output = fopen("php://output", "w");
$query ="SELECT CONCAT('<CALLop:', LENGTH(CALLop), '>',CALLop, ' <qso_date:', LENGTH(qso_date), '>',qso_date, ' <timek:', LENGTH(timek), '>',timek, ' <bands:', LENGTH(bands), '>',bands, ' <eor>') AS x FROM log ORDER BY timek desc";
$result = mysqli_query($connect, $query);
fwrite($output, 'ADIF Export from BKLOG, conforming to ADIF standard specification V 2.00'."\r\n");
fwrite($output, '<PROGRAMID:3>LOG <PROGRAM VERSION:1>6 '."\r\n");
fwrite($output, '<eoh>'."\r\n");
while($row = mysqli_fetch_array($result))
{
fwrite($output, $row['x']."\r\n");
}
fclose($output);
}
?>هذا رابط لتجربة التعديل
http://csvexport.000webhostapp.com

