$conn = mysqli_connect("$host", "$username", "$password")or die("cannot connect");
mysqli_select_db($conn,"$db_name")or die("cannot select DB");
以下代码试图获取MYSQL表并创建表格的标题和列,以便在pdf页面上打印。
$result=mysqli_query($conn,"select Employee_number,date_start,date_end,Days_taken,Sick,Study,Annual,compassionate_leave,Other,Details,Status,approved_by from $tbl_name ");
$number_of_products = mysqli_num_rows($result);
//Initialize the 3 columns and the total
$column_Employee_number = "";
$column_date_start = "";
$column_date_end = "";
$column_Days_taken = "";
$column_Sick = "";
$column_Study = "";
$column_Annual = "";
$column_compassionate_leave = "";
$column_Other = "";
$column_Details = "";
$column_Status = "";
$column_approved_by = "";
$total = 0;
//For each row, add the field to the corresponding column
while($row = mysqli_fetch_array($result))
{
$Employee_number = $row["Employee_number"];
$date_start = $row["date_start"];
$date_end = $row["date_end"];
$Days_taken = $row["Days_taken"];
$Sick = $row["Sick"];
$Study = $row["Study"];
$Annual = $row["Annual"];
$compassionate_leave = ["compassionate_leave"];
$Other = $row["Other"];
$Details = $row["Details"];
$Status = $row["Status"];
$Other = $row["Other"];
$approved_by =$row["approved_by"];
$column_Employee_number =$column_Employee_number.$Employee_number."\n";
$column_date_start = $column_date_start.$date_start."\n";
$column_date_end = $column_date_end.$date_end."\n";
$column_Days_taken = $column_Days_taken.$Days_taken."\n";
$column_Sick = $column_Sick.$Sick."\n";
$column_Study = $column_Study.$Study."\n";
$column_Annual = $column_Annual.$Annual."\n";
$column_compassionate_leave = $column_compassionate_leave.$compassionate_leave."\n";
$column_Other = $column_Other.$Other."\n";
$column_Details = $column_Details.$Details."\n";
$column_Status = $column_Status.$Status."\n";
$column_approved_by = $column_approved_by.$approved_by."\n";
}
从上面的代码我得到一个错误说
注意:第64行的C:\ xampp \ htdocs \ Namtax \ leave_view.php中的数组到字符串转换
是这一行
$column_compassionate_leave = $column_compassionate_leave.$compassionate_leave."\n";
我似乎不明白为什么错误仅针对该行显示,而不是其余部分以及如何修复它的任何帮助?
答案 0 :(得分:1)
您有此代码
$compassionate_leave = ["compassionate_leave"];
其数组,更改为
$compassionate_leave = $row["compassionate_leave"];
答案 1 :(得分:0)
更改$compassionate_leave = ["compassionate_leave"];
$compassionate_leave = $row["compassionate_leave"];
答案 2 :(得分:0)
$compassionate_leave = ["compassionate_leave"];
这一行将是
$compassionate_leave = $row["compassionate_leave"];