亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 php 從 mysql 導出數據?

如何使用 php 從 mysql 導出數據?

PHP
米脂 2022-11-04 16:33:57
我使用 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";

}

考慮其他值,如空值等。


PHP 參考


查看完整回答
反對 回復 2022-11-04
  • 1 回答
  • 0 關注
  • 128 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號