I need to generate an excel report populated from mysql database. I have already made it worked, which generates a report in excel.
But in one column of that report I need to populate the number of pending cases.
Database Details:
one h_id has many sl_id.
one sl_id has many pending cases listed as ENUM M,I.
I need to find the total number of rows of pending cases per sl_id.
Here is my code:
$value = $_POST['hospitalname'];
if($_POST["Submit"]=="Submit") {
for ($i=0; $i<sizeof($value); $i++) {
$sql = "SELECT sl_id from mfb_servicelog where h_id LIKE ('".$value[$i]."')";
$result = mysql_query($sql);
$slid = array();
while ($row = mysql_fetch_assoc($result)) {
if (!in_array($row["sl_id"], $slid)) {
$slid[] = $row["sl_id"];
}
}
foreach($slid as $id) {
$query = "SELECT info_type from mfb_agent_status_details where info_type = 'M' and sl_id LIKE ('".$id."')";
$resultpending = mysql_query($query);
$num_rows = mysql_num_rows($resultpending);
echo "$num_rows\n";
}
}
}
Above code returns number of pending cases per sl_id together like
0 0 0 0 0 2 1 0 1 0 0 2 0 1 0 0 1 0 0 0 1 1 1 0
How to put these to an array so that I can export these to the excel sheet using below code
if ($result1 = mysql_query($query1) or die(mysql_error())) {
while ($rowhos = mysql_fetch_row($result1)) {
$hospitalname[$i] = $rowhos;
if($i == 0) {
$col = 'D';
}
else{
$col = $k;
}
foreach($rowhos as $cell) {
$objPHPExcel->getActiveSheet()->setCellValue($col.$rowhosname,$cell);
$col++;
}
$rowhosname++;
}
}
echo "$num_rows\n";to$yourArray[] =$num_rows;?$iincrementing, the$youArray[$i]will equate to$yourArray[0]/$yourArray[1]/etc