1
$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.

 $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

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 ?

1
  • $compassionate_leave = ["compassionate_leave"]; should be $compassionate_leave = $row["compassionate_leave"];? Commented Apr 6, 2016 at 11:51

3 Answers 3

1

You have this code

 $compassionate_leave = ["compassionate_leave"];

its array, change to

$compassionate_leave = $row["compassionate_leave"];
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0
$compassionate_leave = ["compassionate_leave"];

This line will be

$compassionate_leave = $row["compassionate_leave"];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.