我使用数字将我的请假状态存储在mysql数据库中。如果数字为1,则请假得到批准;如果数字为2,则请假被拒绝。现在我现在面临的问题是我不知道如何使用php将数字转换为字符串。我希望在已导出的.csv文件中获得批准和拒绝的单词。现在只显示数字1和2。
$query ="SELECT tblemployees.FirstName,tblemployees.LastName,tblemployees.EmpId,tblemployees.Gender,tblemployees.Phonenumber,tblemployees.EmailId,applyleave.id,applyleave.LeaveType,applyleave.FromDate,applyleave.duration,applyleave.ToDate,applyleave.descr,applyleave.PostingDate,applyleave.sta,applyleave.adminRemark,applyleave.AdminRemarkDate from applyleave inner join tblemployees on applyleave.employeeID=tblemployees.EmpId";
$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>
';
}
$output .= '</table>';
header('Content-Type: application/xls');
header('Content-Disposition: attachment; filename='. date('Y-m-d') .' Leave Balance.xls');
echo $output;
您的错误是您要附加点.
。变量并使用单引号。单引号上的变量不会被解释,其值也不会返回。
//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";
}
考虑其他值,例如null等。>