Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic bind_result on PHP
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/5300365/dynamically-bind-mysqli-stmt-parameters-and-then-bind-result-php">Dynamically bind mysqli_stmt parameters and then bind result (PHP)</a> </p> </blockquote> <p>can any one help me on how could I create a dynamic bind_result on PHP. My query field doesn't know how many fields are there since it was created dynamically (e.g creating year fields base on the date range). below is my script and highlighted on where is the problem.</p> <pre><code>public function getMarketingReports($datefrom,$dateto) { $yearfrom = date("Y", strtotime($datefrom)); $yearto = date("Y", strtotime($dateto)); //create year fields $concatYear = ""; for($year=$yearfrom;$year&lt;=$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-&gt;stmt_init(); if($stmt-&gt;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-&gt;bind_param("ss",$datefrom,$dateto); $stmt-&gt;execute(); $stmt-&gt;bind_result ( $positionCode, $positionName, $location, **//getting bind result data here for year fields** $totalEmployees ); while($stmt-&gt;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; } </code></pre> <p>Is it possible? Can anyone help me on how could I solve this problem</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload