score:1
after looking at the image again, i can understand your problem. you basically need to prepare your data, instead of printing the pdf directly.
you could use a map to calculate your output like so:
$total = array("freq" => 0, "menit" => 0, "jam" => 0);
$groups = array();
while ($data = mysqli_fetch_array($query)) {
$names = explode(",",$data['nama_tmp']);
foreach ($names as $name) {
if (!array_key_exists($name, $groups)) {
$groups[$name] = array("freq" => 0, "menit" => 0, "jam" => 0);
}
$groups[$name]["freq"] += $data["freq"];
$groups[$name]["menit"] += $data["menit"];
$groups[$name]["jam"] += $data["jam"];
$total["freq"] += $data["freq"];
$total["menit"] += $data["menit"];
$total["jam"] += $data["jam"];
}
}
now you should have all your data in $groups and you can generate your pdf from that.
foreach ($groups as $name => $group) {
$pdf->ln();
$pdf->cell(90,5,$name,1,0,'l',0);
$pdf->cell(20,5,$group['freq'],1,0,'c',0);
$pdf->cell(25,5,$group['menit'],1,0,'c',0);
$pdf->cell(25,5,$group['jam'],1,0,'c',0);
}
$pdf->ln(5);
$pdf->setfillcolor(255, 235, 255);
$pdf->setfont('times','b',8);
$pdf->cell(90,5,'total',1,0,'c',1);
$pdf->cell(20,5,$total["freq"],1,0,'c',1);
$pdf->cell(25,5,$total["menit"],1,0,'c',1);
$pdf->cell(25,5,$total["jam"],1,0,'c',1);
note: instead of using a variable for every column sum, i have used a $total map array instead. this makes it more readable. also you should consider using some functions for each part of your script.
the main function could then be as simple as this:
$data = readdata();
$groups= calculatesums($data);
$pdf = generatepdf($groups);
Source: stackoverflow.com
Related Query
- how to COUNT explode imploding data with comma?
- How to have multiple highcharts with different series data in vuejs without repeating code
- How to change value with count data
- How to display highchart y axis with constistant data
- How to structure Angular with Highcharts and lots of dynamic data
- Highcharts - Global configuration with common code and unique data & Headings
- How to populate a Highcharts axis with string formatted data from a PHP array
- How to handle HighCharts zooming with large data sets
- Data with timestamp group to month(like Jan, Feb, March) and showing as total count for month in Highcharts
- How can I force ticks/grid lines on a Highcharts datetime X axis to arbitrarily line up with data points?
- How to achieve the best possible performance with mutable data and real-time charts in React?
- Codeigniter highcharttable count how many data in a month
- How can i get the json data with the specific between Year?
- How to Build a Column Chart in Highcharts with Data Entered Dynamically Within a CMS
- How to input plot data into highcharts with rails
- how to pass datalabels along with data to show it in tooltip in highchart
- How to align Highcharts datetime x-axis with data I pass to it?
- HighCharts & MVC: How to load whole graph definition and data with JSON?
- Highstock, True way of Get count of shown points after setExtreme (Zooming) - WITHOUT counting all data with MIN and MAX
- How to show count of data in pie-chart in chartkick rails
- How make a growth baby chart with data in mysql +PDO
- How can I have both a legend and data labels, with different labels, in Highcharts?
- Highcharts bar with negative stack: how to position data labels
- How to specify a range of data when using HighCharts with <table>?
- How to make a chart with highcharts, load data from API
- How to create pie chart with only 1 series data and have background be a circle
- How to display percentage along with Count value in Pie chart Using Higcharts Plugin?
- Have an issue with JavaScript, AJAX code displaying data
- How to add percent symbol with data inside column in highchart?
- How to push data into highchart with just one decimal place?
More Query from same tag
- Resize height with Highcharts
- Ionic 3 Highcharts not visible
- What should I do to make the x-axis of a graph bold with Highchart?
- JQuery animation doesn't work in IE8
- How to use dblclick event in highcharts?
- How do i limit the range of the x or y value in High charts?
- Making a dataLabel draggable
- JSON for high chart imported with json.load generated error when using json.dump
- How to show multiple sets in a Highcharts Venn chart?
- Switching position of checkbox and title of serie
- How to handle mousedown event on chart part?
- change button image
- Can't get events to work on images with Highmaps
- Get value in province label with highmaps in the highcharter package
- add a point on mouse click event on highcharts
- Cannot update Highcharts series in click event with highcharts-ng
- High charts - Increasing the space between chart and title
- lazy high charts rails, what is "my_id" ? in <%= high_chart("my_id4", @chart) %>
- Line to the Y axis on hover
- How to truncate value in tooltip using highcharts
- highcharts stacked area with irregular x-intervals
- Cannot give different values to diffrent Bar item click in HighChart
- Highcharts Non-Identical Time Series
- How to put date into drilldown chart title based on drilled point x value (datetime)..?
- Label Y-Axis stops in Highcharts solid gauges
- Highlight multiple series in Highcharts
- Override default highlighting on hover in networkgraph
- Highcharts show all categories even when no data
- GWT Highchart comparing series
- Removing gaps before first and after last columns in Highcharts