I have a form that has fields that auto populate with data from mysql table. Specifically two checkbox input fields for two types of roles; instructor
and contact
. I initially I stored values the values in the table as either 1
or 0
to signify true
or false
. A person can be one or the other, neither or both. When I try to display those values through a checkbox I am not getting a result. If the value of in the table for a particular role is 1
I want to have the checkbox checked
. I am getting no results.
DB query and display:
$db_select = $db_con->prepare("
SELECT a.name,
a.academy_id,
p.contact_role,
p.instructor_role
FROM academy a
LEFT JOIN person p ON a.academy_id = p.academy_id
WHERE a.academy_id = :id
");
if (!$db_select) return false;
if (!$db_select->execute(array(':id' => $id))) return false;
$results = $db_select->fetchAll(\PDO::FETCH_ASSOC);
if (empty($results)) return false;
$result = '';
foreach ($results as $value){
$result .= "<ul>";
$result .= "<li><input id=\"person_contact\" name=\"person_contact\" type=\"checkbox\"". $contact_role = $value2['contact_role'] == "1" ? "checked='checked'" : "" ." />Concact</li>";
$result .= "<li><input id=\"person_instructor\" name=\"person_instructor\" type=\"checkbox\"". $instructor_role = $value2['instructor_role'] == "1" ? "checked='checked'" : "" ."/>Instructor</li>";
$result .= "</ul>";
$s++;
}