how to put mysql generated values in an php array -
i need generate excel report populated mysql database. have made worked, generates report in excel.
but in 1 column of report need populate number of pending cases.
database details:
one h_id has many sl_id.
one sl_id has many pending cases listed enum m,i.
i need find total number of rows of pending cases per sl_id.
here code:
$value = $_post['hospitalname']; if($_post["submit"]=="submit") { ($i=0; $i<sizeof($value); $i++) { $sql = "select sl_id mfb_servicelog h_id ('".$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 $id) { $query = "select info_type mfb_agent_status_details info_type = 'm' , sl_id ('".$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 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 put these array can export these 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 $cell) { $objphpexcel->getactivesheet()->setcellvalue($col.$rowhosname,$cell); $col++; } $rowhosname++; } }
i going assume mfb_agent_status_details table has id attribute (you can use unique field in table, maybe it's called asd_id example):
$sql = "select mfb_servicelog.sl_id, count(mfb_agent_status_details.*) count mfb_servicelog left join mfb_agent_status_details on mfb_servicelog.sl_id = mfb_agent_status_details.sl_id mfb_servicelog.h_id ('".$value[$i]."') group mfb_servicelog.sl_id";
now each resulting rows "count" attribute can insert excel.
Comments
Post a Comment