I'm not sure what I'm doing wrong. My code should read user_id from users table in mysql then use that in the next sql statement to read a line of sales for that sales person for the past week and then generate into a PDF. On line 56, I'm getting a Catchable fatal error: Object of class PDOStatement could not be convert to string, but as far as I can tell it should be a string. Any help would be greatly appreciated!
for($i=0;$i<$user_array;$i++) {
$uid = $user_array[$i];
try {
//Create connection
$con = new PDO("mysql:host=$servername; dbname=$database", $username, $password);
$con->exec("SET CHARACTER SET utf8");
}
catch(PDOException $ee) {
echo $ee->getMessage();
}
$con->beginTransaction();
$query = "SELECT CONCAT(fname,' ',lname) FROM users WHERE user_id = '$uid'";
$result = $con->query($query);
if($result !== false) {
//This throws catchable fatal error: Object of class PDOStatement could not be converted to string - line 56
$sql = "select saledate, custname, straddr from dplgalionsales
WHERE CONCAT(agent_first_name,' ',agent_last_name) = '$result' //<-- line 56
and saledate > DATE_SUB(NOW(), INTERVAL 1 WEEK)";
foreach($res->query($sql) as $row) {
$mydate = date('m/d/Y');
$dateadd = date('m/d/Y', strtotime($mydate.' + 3 days'));
$html_table = '<div>Week Ending: ' .$mydate. '<br>Payroll Issued: ' .$dateadd. '</div><br>';
$html_table .= '<table border="1" cellspacing="0" cellpadding="2" width="100%"><tr><th>Date</th><th>Customer Name</th><th>Address</th></tr>';
$html_table .= '<tr><td>' .$row['saledate']. '</td><td>' .$row['custname']. '</td><td>' .$row['straddr']. ' ' .$row['city']. ' ' .$row['state']. ' ' .$row['zip']. '</td></tr>';
$html_table .= '</table>'; //ends HTML table
}
}
$mpdf = new mPDF();
$mpdf->SetTitle('DPL Galion Sales');
$mpdf->WriteHTML($html_table);
$mpdf->Output('./reports/'.$uid.'/'.date('m-d-Y').'_'.$uidname.'.pdf','F');
exit;
}
I was wondering if it has something to do with the MySQL CONCAT()? I don't really know a better way to match the salesperson's info though, because first and last name are separate and the sales reporting comes in without their sales ID on it, so name is the only reference point between the two tables. Thanks!