PHPで動的bind_resultを作成する方法について誰かが私を助けてくれますか?クエリフィールドは動的に作成されたため、フィールドがいくつあるかわかりません(たとえば、日付範囲に基づいて年フィールドを作成します)。以下は私のスクリプトであり、問題がどこにあるかを強調しています。
public function getMarketingReports($datefrom,$dateto)
{
$yearfrom = date("Y", strtotime($datefrom));
$yearto = date("Y", strtotime($dateto));
//create year fields
$concatYear = "";
for($year=$yearfrom;$year<=$yearto;$year++){
$concatYear .= "SUM(IF(c.datecreated='".$year."',IF(LOWER(c.fullTimeEployeeType)='basic hour rate', c.fullTimeEployeeTypeAmount*2080 , c.fullTimeEployeeTypeAmount),0)) ".$year.",";
}
$reportdata = array();
$db = Connection::Open();
$stmt = $db->stmt_init();
if($stmt->prepare("SELECT p.Code `PositionCode`,
p.name `PositionName`,
l.value `Location`,
".$concatYear."
SUM(b.field205) `TotalEmployees`
FROM c1 c
INNER JOIN b1 b
ON c.registrationid=b.id
INNER JOIN positions p
ON c.positionid=p.id
INNER JOIN lookupvalues l
ON c.location=l.id
WHERE c.`status`!=2
AND c.datecreated BETWEEN ? AND ?
GROUP BY c.positionid,c.location,YEAR(c.datecreated)")){
$datefrom = $datefrom." 00:00:00";
$dateto = $dateto." 23:59:59";
$stmt->bind_param("ss",$datefrom,$dateto);
$stmt->execute();
$stmt->bind_result
(
$positionCode,
$positionName,
$location,
**//getting bind result data here for year fields**
$totalEmployees
);
while($stmt->fetch())
{
$surveydata = array();
$surveydata['positionCode'] = $positionCode;
$surveydata['positionName'] = $positionName;
$surveydata['location'] = $location;
**//storing of data here for year fields**
$surveydata['totalEmployees'] = $totalEmployees;
array_push($reportdata,$surveydata);
}
}
Connection::Close();
return $reportdata;
}
出来ますか?誰かがこの問題をどのように解決できるかについて私を助けることができますか