有一个数组到字符串转换错误

时间:2022-07-14 16:31:26
$conn = mysqli_connect("$host", "$username", "$password")or die("cannot connect"); 
mysqli_select_db($conn,"$db_name")or die("cannot select DB");

the below code is trying to get the MYSQL table and create the headers and columns for the table to print on a pdf page.

下面的代码试图获取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";

}

from the above code i get a error saying

从上面的代码我得到一个错误说

Notice: Array to string conversion in C:\xampp\htdocs\Namtax\leave_view.php on line 64

注意:第64行的C:\ xampp \ htdocs \ Namtax \ leave_view.php中的数组到字符串转换

which is this line

这是这条线

$column_compassionate_leave = $column_compassionate_leave.$compassionate_leave."\n"; 

and i dont seem to understand why the error is showing only for that line and not for the rest and any help on how to fix it ?

我似乎不明白为什么错误只显示该行,而不是其余的和任何帮助如何解决它?

3 个解决方案

#1


1  

You have this code

你有这个代码

 $compassionate_leave = ["compassionate_leave"];

its array, change to

它的数组,改为

$compassionate_leave = $row["compassionate_leave"];

#2


0  

change your $compassionate_leave = ["compassionate_leave"]; it should be $compassionate_leave = $row["compassionate_leave"];

改变你的$ compassionate_leave = [“compassionate_leave”];它应该是$ compassionate_leave = $ row [“compassionate_leave”];

#3


0  

$compassionate_leave = ["compassionate_leave"];

This line will be

这条线将是

$compassionate_leave = $row["compassionate_leave"];

#1


1  

You have this code

你有这个代码

 $compassionate_leave = ["compassionate_leave"];

its array, change to

它的数组,改为

$compassionate_leave = $row["compassionate_leave"];

#2


0  

change your $compassionate_leave = ["compassionate_leave"]; it should be $compassionate_leave = $row["compassionate_leave"];

改变你的$ compassionate_leave = [“compassionate_leave”];它应该是$ compassionate_leave = $ row [“compassionate_leave”];

#3


0  

$compassionate_leave = ["compassionate_leave"];

This line will be

这条线将是

$compassionate_leave = $row["compassionate_leave"];