我使用 numberic 將我的休假狀態存儲在 mysql 數據庫中。如果編號為 1 則批準請假,如果編號為 2 則請假已被拒絕。現在我現在面臨的問題是我不知道如何使用 php 將數字轉換為字符串。我希望在我導出的 .csv 文件中獲得批準和拒絕這個詞?,F在它只顯示數字 1 和 2 。 $result = mysqli_query($db, $query); if(mysqli_num_rows($result) > 0) { $output .= ' <table class="table" bordered="1"> <tr> <th>No</th> <th>Employee ID</th> <th>Employee Name</th> <th>Employee Email</th> <th>Employee Contact Number</th> <th>Leave Type</th> <th>From Date</th> <th>To Date</th> <th>Duration</th> <th>Reason</th> <th>Leave Status</th> <th>Request Date</th> <th>Admin Remark</th> <th>Admin Remark Date</th> </tr> '; while($row = mysqli_fetch_array($result)) { $sta='.$row["sta"].'; if($sta==1){ $status="Approved"; } if($sta==2){ $status="Rejected"; } $output .= ' <tr> <td>'.$row["id"].'</td> <td>'.$row["EmpId"].'</td> <td>'.$row["LastName"].' '.$row["FirstName"].'</td> <td>'.$row["EmailId"].'</td> <td>'.$row["Phonenumber"].'</td> <td>'.$row["LeaveType"].'</td> <td>'.$row["FromDate"].'</td> <td>'.$row["ToDate"].'</td> <td>'.$row["duration"].'</td> <td>'.$row["descr"].'</td> <td>'.$status.'</td> <td>'.$row["PostingDate"].'</td> <td>'.$row["adminRemark"].'</td> <td>'.$row["AdminRemarkDate"].'</td> </tr> '; }
1 回答

largeQ
TA貢獻2039條經驗 獲得超8個贊
您的錯誤是您要附加點.。到變量并使用單引號。單引號上的變量不會被解釋并且它們的值不會被返回。
//Your code
$sta='.$row["sta"].'; // This will save on $sta ( .$row["sta"]. ) because you are using single quotes.
// Update to
$sta=$row["sta"]; // you don't need quotes or dots in the variable
還有 if 語句,我會將其更改為:
if($sta==1){
$status="Approved";
}else if($sta==2){
$status="Rejected";
}else{
$status = "Not Defined";
}
考慮其他值,如空值等。
- 1 回答
- 0 關注
- 128 瀏覽
添加回答
舉報
0/150
提交
取消