-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathExample.php
More file actions
51 lines (43 loc) · 2.06 KB
/
Example.php
File metadata and controls
51 lines (43 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!--
You can include any HTML/CSS you need
here including sample CSS
-->
<link rel="stylesheet" href="style.css" />
<h2>Jump to:</h2>
<ul>
<li><a href="#genre">Films by Genre</a></li>
<li><a href="#actorGenre">Films by Actor and Genre</a></li>
<li><a href="#actorYear">Films by Genre and Year</a></li>
</ul>
<?php
require '../PHPivot.php';
//Get the data
//Could be from a database, JSON, etc
//Just needs to be saved in an associative PHP array
//First row: headers, subsequent rows: data
//here: read JSON and make associative array
$data = json_decode(file_get_contents('FilmDataSet.json'), true);
echo '<a name="genre"></a><h1>Films by Genre</h1>';
$filmsByGenre = PHPivot::create($data)
->setPivotRowFields('Genre')
->setPivotValueFields('Genre',PHPivot::PIVOT_VALUE_COUNT, PHPivot::DISPLAY_AS_VALUE_AND_PERC_COL, 'Frequency of Genre')
->addFilter('Genre','', PHPivot::COMPARE_NOT_EQUAL) //Filter out blanks/unknown genre
->generate();
echo $filmsByGenre->toHtml();
echo '<a name="actorGenre"></a><h1>Films by Actor and Genre</h1>';
$filmsByActorAndGenre = PHPivot::create($data)
->setPivotRowFields('Actor')
->setPivotColumnFields('Genre')
->setPivotValueFields('Genre',PHPivot::PIVOT_VALUE_COUNT, PHPivot::DISPLAY_AS_VALUE_AND_PERC_ROW, 'Frequency of Genre by Actor')
->addFilter('Genre','', PHPivot::COMPARE_NOT_EQUAL) //Filter out blanks/unknown genre
->generate();
echo $filmsByActorAndGenre->toHtml();
echo '<a name="actorYear"></a><h1>Films by Genre and Year</h1>';
$filmsByGenreAndYear = PHPivot::create($data)
->setPivotRowFields(array('Year','Genre'))
->setPivotValueFields('Genre',PHPivot::PIVOT_VALUE_COUNT, PHPivot::DISPLAY_AS_VALUE, 'Frequency of Genre in each year')
->addFilter('Genre','', PHPivot::COMPARE_NOT_EQUAL) //Filter out blanks/unknown genre
->setIgnoreBlankValues()
->generate();
echo $filmsByGenreAndYear->toHtml();
?>