嗨,我的代码运行良好,并且将我的所有数据都提取到了 excel 表中……但它的格式不正确……如果我想将数据写入表格格式怎么办,看起来像这样……正如我提到的以下
<table border="0" cellspacing="0" cellpadding="0" >
<tbody>
<tr> <input name="id" type="hidden" value="<?php echo $data['0']; ?>" >
<td><?php echo $data['2']; ?></td>
<td><?php echo $data['3']; ?></td>
<td><?php echo $data['8']; ?></td>
<td><?php echo $data['9']; ?></td>
<td><?php echo $data['11']; ?></td>
<td><?php echo $data['12']; ?></td>
<td><?php echo $data['4']; ?></td>
<td><?php echo $data['5']; ?></td>
<td><?php echo $data['6']; ?></td>
<td><?php echo $data['13']; ?></td>
<td><?php echo $data['10']; ?></td>
<td><?php echo $data['14']; ?></td>
<td><input name="edit" type="submit" value="Edit">
<input name="BOOK" type="submit" value="Book" style="color:#d90f0f">
</td>
</tr>
</tbody>
</table>"
<?php
include 'functions.php';
ob_start();
if($_POST['types'] == 'name') {
$query = "SELECT * FROM visitor_detail WHERE name='".$_POST['filter']."' ORDER BY id DESC ";
}
elseif($_POST['types'] == 'mobile') {
$query = "SELECT * FROM visitor_detail WHERE mobile='".$_POST['filter']."' ORDER BY id DESC ";
}
elseif($_POST['types'] == 'OccasionType') {
$query = "SELECT * FROM visitor_detail WHERE OccasionType='".$_POST['filter']."' ORDER BY id DESC ";
}
elseif($_POST['types'] == 'InquiryDate') {
$query="SELECT * FROM visitor_detail WHERE TodayDate between '".$_POST['From']."' and '".$_POST['TO']."' ORDER BY id DESC " ;
}
elseif($_REQUEST['types'] == 'OccasionDate') {
$que="SELECT * FROM visitor_detail WHERE date between '".$_REQUEST['From']."' and '".$_REQUEST['To']."' ORDER BY id DESC ";
}
else {
$query = "SELECT * FROM visitor_detail ORDER BY id DESC ";
}
$sql = mysql_query($query);
$line1="Id\tgender\tname\tmobile\taddress\temail\totherno\tzipcode\tOccasionType\tdate\tgue st\tdescription\tTodayDate\tauther\t";
$data="$line1\n";
$br = '<br>';
$fileName = "./my.txt";
$file = fopen($fileName, "w");
fwrite($file, $data."\n");
$i=1;
while($row = mysql_fetch_assoc($sql))
{
$line2=$i . "\t" . $row['gender'] . "\t" . $row['name'] . "\t" . $row['mobile'] . "\t" . $row['address'] . "\t" . $row['email'] . "\t" . $row['otherno'] . "\t" . $row['zipcode'] . "\t" . $row['OccasionType'] . "\t" . $row['date'] . "\t" . $row['guest'] . "\t" . $row['description'] . "\t" . $row['TodayDate'] . "\t" . $row['auther'] . "\t";
$data1=$line2.$br;
echo $data1;
fwrite($file, $data1);
$i++;
}
fclose($file);
header('Content-Type: application/csv');
header('Content-Disposition: attachment; filename=my.csv');
header('Pragma: no-cache');
fclose($file); ?>