這是我的導出代碼。只是想以零爲首,因爲這是我每個學生的獨特代碼,但是在我輸出爲excel後,零點消失了。我想要做什麼。如何從php中導出爲零的excel
function db_connect(){
include('dbcon.php');
if ($dbcon->connect_error) {
die("Connection failed: " . $dbcon->connect_error);
}
return $dbcon;
}
$filename ="Users.xls";
header('Content-type: application/ms-excel');
header('Content-Disposition: attachment;filename='.$filename);
$sql = "SELECT * FROM member";
$dbcon = db_connect();
if($dbcon){
$result = $dbcon->query($sql);
echo "User ID\tFNAME\tLNAME\tTYPE\tCOURSE\tYEAR LEVEL\tCODE\n"; // prints header line with field names
if ($result->num_rows > 0) {// output data of each row
while($row = $result->fetch_assoc()) {
echo $row['stud_num']."\t".$row['firstname']."\t".$row['lastname']."\t". $row['type']."\t".$row['course']."\t".$row['year_level']."\t".$row['code']."\n";// prints each record with five fields in a row
}
}
}
前置單引號應該可以工作。 –
@TimWilliams我在代碼中會改變什麼? –