<?php
include("_dbconn.php");
$area = isset($_GET["area"])? $_GET["area"] : "";
if(substr($area,-1) == "|"){
$area = substr($area,0,-1);
}
$area_list = explode("|",$area);
$area_clause = " area_no in ('" . implode("','", $area_list) . "')";
$ary_approver = array(
"Albert Chin" => "albert.chin@example.com",
"Alberto Leotti" => "alberto.leotti@example.com",
"Alex Koh" => "alex.koh@eg.com",
"Bala Subbu" => "bala.subbu@eg.com",
"Bertrand Seow" => "bertrand.seow@eg.com",
"Calvin Goh Chin Boon" => "calvin.goh@eg.com",
"Chan Boon Hock" => "boon-hock.chan@eg.com",
"Cheng Kear Yong" => "kear-yong.cheng@eg.com",
"Cheng Kong Meng" => "kong-meng.cheng@eg.com",
"Chia Yeow Chong" => "yeowchong.chia@eg.com",
"Chong Chan Sin" => "chan-sin.chong@eg.com",
"Daniel Tan" => "yung-an.tan@eg.com",
"Dominic Tay" => "dominic.tay@eg.com",
"Eddie Lim" => "eddie.lim@eg.com",
"Gordon Mckee" => "gordon.mckee@eg.com",
"Ignatius Ong" => "ignatius.ong@eg.com",
"Jacynthia Khor" => "jacynthia.khor@eg.com",
"Jasmine Yeo" => "jasmine.yeo@eg.com",
"Joe Tan" => "joe.tan@eg.com",
"Ken Leong" => "ken.leong@eg.com",
"Kim Myung Sung" => "ms.kim@eg.com",
"Lee Chee Kit" => "chee-kit.lee@eg.com"
);
$sql = "Select distinct(approver_name) from access_request.tbl_access_area where ".$area_clause."";
$result = mysqli_query($conn,$sql);
$cnt = 0;
echo "<table align=\"center\" border=\"0\" width=\"95%\" bordercolor=\"#DADADA\" cellpadding=\"3\" cellspacing=\"1\">\n";
echo "<tr bgcolor=\"#F5F5F5\"><td align=\"left\" colspan=\"5\">\n";
echo "<font face=\"arial\" size=\"2\" color=\"#3C5F84\"> Approver </font>";
echo " ";
echo "<tr bgcolor=\"#F5F5F5\"><td align=\"left\" colspan=\"5\" style=\"
display: grid;
grid-template-columns: max-content max-content max-content max-content max-content max-content max-content max-content;
grid-gap: 10px;
margin-left:138px;
margin-top:-23px;\">";
while($row = mysqli_fetch_array($result)){
foreach($ary_approver as $k => $v){
if($k == $row["approver_name"]){
echo "<input type=\"checkbox\" id=\"chkApprover" . $cnt . "\" name=\"chkApprover[]\" value=\"$v\"><font face=\"arial\" size=\"2\" color=\"#3C5F84\">". $k . "</font>";
}
}
$cnt++;
}
echo "</td></tr>\n";
echo "</td></tr>\n";
echo "<tr bgcolor=\"#F5F5F5\"></tr>\n";
echo "</table>\n";
?>
What I have tried:
Above codes are from full php and I will provide JS part in down below.
<pre>var alist = '';
var list = document.getElementsByName('chkApprover[]');
for ( i=0; i < list.length; i++ ) {
if (document.getElementById('chkApprover' + i).checked == true) {
alist = alist + list[i].value + '|';
}
}
if(alist == ""){
alert("Please choose Approver !");
return false;
}