In my php file, I query a view and then assign the result to Smarty variables.
$sql = "";
$date_range = false;
$conditions = [];
$parameters = [];
if(strlen($_GET['eid'])>0){
$eid = $_GET['eid'];
$parameters[] = $eid;
$conditions[] = "employee_id = ?";
}
else
{
$eid = '';
}
if(strlen($_GET['tid'])>0){
$tid = $_GET['tid'];
$parameters[] = $tid;
$conditions[] = "training_id = ?";
}
else
{
$tid = '';
}
debug_to_console('starting date value ' .$_GET['sd']);
if(strlen($_GET['sd']) > 0){
$sd = $_GET['sd'];
$date_range = 'true';
}
else
{
$date_range = 'false';
$sd = '';
}
debug_to_console('ending date value ' .$_GET['ed']);
if(strlen($_GET['ed']) > 0){
$ed = $_GET['ed'];
$date_range = 'true';
}
else
{
$date_range = 'false';
$ed = '';
}
if ($date_range == 'true')
{
$conditions[] = "class_date BETWEEN ? AND ?";
$parameters[] = $sd;
$parameters[] = $ed;
}
$sql = "SELECT COUNT(*) from viewSingleTraining";
if($conditions)
{
$sql .= " WHERE ".implode(" AND ", $conditions);
}
$stmt = $pdo->prepare($sql);
$stmt->execute($parameters);
$total_pages = $stmt->fetchColumn();
$sql = "SELECT * from viewSingleTraining";
if($conditions)
{
$sql .= " WHERE ".implode(" AND ", $conditions);
}
$sql .= " LIMIT ?, ?";
$stmt = $pdo->prepare($sql);
$parameters[] = $offset;
$parameters[] = $records_per_page;
$stmt->execute($parameters);
$rows = $stmt->fetch(PDO::FETCH_ASSOC);
$smarty->assign('rows', $rows);
$smarty->assign('pageno', $pageno);
$smarty->assign('eid', $eid);
$smarty->assign('tid', $tid);
$smarty->assign('sd', $sd);
$smarty->assign('ed', $ed);
$smarty->assign('total_pages', $total_pages);
$smarty->assign('dir', $INC_DIR);
$smarty->display($INC_DIR. '/views/searchresult.tpl');
In the .tpl file I loop the $rows array to build a table like this
{foreach $rows as $r}
<tr>
<td>{$r.fullname}</td>
<td>{$r.department}</td>
<td>{$r.class_title}</td>
<td>{$r.class_date}</td>
<td>{$r.class_end_date}</td>
<td>{$r.class_hours}</td>
<td><input type="checkbox" style="margin:5px;" class="form-check-input" {if $r.cfs =='1'}checked="checked"{/if}></td>
<td><input type="checkbox" style="margin:5px;" class="form-check-input" {if $r.cea =='1'}checked="checked"{/if}></td>
<td><input type="checkbox" style="margin:5px;" class="form-check-input" {if $r.ceu =='1'}checked="checked"{/if}></td>
</tr>
{/foreach}
For each column in the table, I get an error like this: Illegal string offset 'fullname' in C:\Bitnami\wampstack-7.3.9-0\apache2\htdocs\templates_c\363f8c8c6607635d87e449dc20506adfdfc7d7b0_0.file.searchresult.tpl.php on line 133
EDIT 10/15/2019 22:11 This is the vardump of values
array(13)
{ ["fullname"]=> string(11) "Randy"
["department"]=> string(14) "Administration"
["id"]=> string(5) "58362"
["training_id"]=> string(1) "3"
["employee_id"]=> string(4) "1101"
["class_title"]=> string(71) "Recipient Rights Training(Classroom/ online) in nonresidentiaal Setting"
["class_date"]=> string(16) "1/9/2017 0:00:00"
["class_end_date"]=> NULL
["class_hours"]=> string(1) "1"
["cfs"]=> string(1) "0"
["cae"]=> string(1) "0"
["ceu"]=> string(1) "0"
["description"]=> string(836) "This training is intended for case managers, therapists, administrative staff, and support staff. In addition to recipient rights as defined by the Michigan Mental Health Code, it includes information concerning Substance Abuse Recipient Rights, Appeals and Grievance, Advance Directives. This training serves as both the refresher and new hire orientation for non residential staff. This training's objectives are as follows: 1. To highlight the rights of recipients guaranteed by the Michigan Mental Health Code. 2. To ensure that employees understand they must report abuse, neglect and other allegations of rights violations. 3. To ensure employees understand when and how to report abuse, neglect and other alleged recipient rights violations. This class mayb e taken in Classroom style at N180 or via N180 online training system"
}
The data in the view is clean. I don't know why this error happens. Thanks for any help.