Reference - Data handling - rows


App: ledger - Page: transactions
PHP
transactions.php
HTML
transactions.pad
Result
<?php

// A month's transactions as one table - sorted and paged on the server by {datatable} -
// narrowed to a category, an account or a word in the note. The same rows answer as CSV
// (?transactions&padFormat=csv) and JSON: $padExpose names them.

$only = (int) padRequest ( 'category', 0 );
$from = (int) padRequest ( 'account', 0 );
$word = trim ( ledgerText ( 'q' ) );

$rows = array_map ( fn ( $r ) => array_diff_key ( $r, [ 'id' => 1, 'kind' => 1 ] ), ledgerRows ( $ledgerMonth, $only, $from, $word ) );
$shown = count ( $rows );
$sum = round ( array_sum ( array_column ( $rows, 'amount' ) ), 2 );

$categoryList = array_map ( fn ( $c ) => $c + [ 'chosen' => $c ['id'] == $only ], ledgerCategories () );
$accountList = array_map ( fn ( $a ) => $a + [ 'chosen' => $a ['id'] == $from ], ledgerAccounts () );
$monthName = ledgerMonthName ( $ledgerMonth );
$csvName = "ledger-$ledgerMonth.csv";
$csvQuery = http_build_query ( [ 'month' => $ledgerMonth, 'category' => $only, 'account' => $from, 'q' => $word, 'padFormat' => 'csv' ] );

$padExpose = [ 'rows' ];
$ledgerPage = "Transactions, $monthName";

?>
<div class="head">
<h1>Transactions <span class="dim">{$monthName}</span></h1>
<a class="button" href="{$padGo}transactions&{$csvQuery}" download="{$csvName}">⬇ CSV</a>
</div>

<form class="filters" method="get">
<input type="hidden" name="transactions" value="">
<input type="hidden" name="month" value="{$ledgerMonth}">
<label>Category
<select name="category"><option value="0">All</option>{categoryList}<option value="{$id}"{if $chosen} selected{/if}>{$name}</option>{/categoryList}</select>
</label>
<label>Account
<select name="account"><option value="0">All</option>{accountList}<option value="{$id}"{if $chosen} selected{/if}>{$name}</option>{/accountList}</select>
</label>
<label>Note <input type="search" name="q" value="{$word}" placeholder="a word"></label>
<button class="button">Show</button>
</form>

<section class="card table">
{if $shown gt 0}
{datatable data='rows', columns='day, category, account, note, amount', format="amount:money, day:date('D j M')", totals='amount', sortable, rows=15, striped}
{else}
<p class="dim">No transactions here.</p>
{/if}
<p class="dim sum">{$shown} transactions, together {$sum | money}.</p>
</section>


App: manual - Page: fragments/charts_2
PHP
HTML
fragments/charts_2.pad
Result
<p>Fibonacci grows fast: {sparkline sequence='fibonacci', rows=12}</p>


App: manual - Page: fragments/pager_1
PHP
fragments/pager_1.php
HTML
fragments/pager_1.pad
Result
<?php

$products
= range ( 1, 47 );

?>
{products page=$pg ?? 1, rows=5}
{$products}
{/products}

{pager 'products', window=1}


App: manual - Page: fragments/pager_2
PHP
fragments/pager_2.php
HTML
fragments/pager_2.pad
Result
<?php

$products
= range ( 1, 47 );

?>
{products page=$p ?? 1, rows=10}{/products}

{pager 'products'}
{if $href eq ''}
<span>{$label}</span>
{elseif $kind eq 'current'}
<strong>{$label}</strong>
{else}
<a href="{$href}">{$label}</a>
{/if}
{/pager}


App: manual - Page: fragments/sequences_2
PHP
HTML
fragments/sequences_2.pad
Result
<p>Primes: {sparkline sequence='prime', rows=20}</p>
<p>Recamán: {sparkline sequence='recaman', rows=40, width=200}</p>


App: manual - Page: miscellaneous/handling


App: regression/errors - Page: syntax/a_select_relation_reads_a_field_of_the_outer_row
PHP
syntax/a_select_relation_reads_a_field_of_the_outer_row.php
HTML
syntax/a_select_relation_reads_a_field_of_the_outer_row.pad
Result
<?php

// The relation is followed by the outer row's customerNumber, and the outer select's
// fields= leaves that field out of its rows.

$padSelect ['custRow'] = [ 'db' => 'customers', 'key' => 'customerNumber' ];
$padSelect ['orderRow'] = [ 'db' => 'orders', 'key' => 'orderNumber' ];

$padRelations ['orderRow'] ['custRow'] = [ 'customerNumber' => 'customerNumber' ];

?>
{custRow rows=1, fields='customerName'}{orderRow}x{/orderRow}{/custRow}


App: regression/framework - Page: options/a_page_below_one_is_the_first_page
PHP
options/a_page_below_one_is_the_first_page.php
HTML
options/a_page_below_one_is_the_first_page.pad
Result
<?php

$items
= [ [ 'n' => 1 ], [ 'n' => 2 ], [ 'n' => 3 ] ];
$pg = 'abc';

?>
{items page=0, rows=2}{$n} {/items}|{items page=-1, rows=2}{$n} {/items}|{items page=$pg, rows=2}{$n} {/items}|{items page=2, rows=2}{$n} {/items}


App: regression/framework - Page: options/a_paged_tag_leaves_now_and_hit_alone
PHP
options/a_paged_tag_leaves_now_and_hit_alone.php
HTML
options/a_paged_tag_leaves_now_and_hit_alone.pad
Result
<?php

$now
= 'app now';
$hit = 'app hit';

?>
{data 'pg'}[{"n":"a"},{"n":"b"},{"n":"c"}]{/data}{pg page=2, rows=2}{$n}{/pg}|{$now}|{$hit}


App: regression/framework - Page: options/negative_inverts_the_window_page_or_start_cut_with_rows_or_end
PHP
HTML
options/negative_inverts_the_window_page_or_start_cut_with_rows_or_end.pad
Result
{data 'n'}
[1,2,3,4,5]
{/data}
[{n page=2, rows=2, negative}
{$n},
{/n}][{n rows=2, page=2, negative}
{$n},
{/n}][{n start=2, end=3, negative}
{$n},
{/n}][{n start=2, rows=2, negative}
{$n},
{/n}][{n end=-1, rows=2, negative}
{$n},
{/n}][{n rows=2, negative}
{$n},
{/n}]


App: regression/framework - Page: options/negative_keeps_the_rows_outside_a_window_sized_beside_it
PHP
HTML
options/negative_keeps_the_rows_outside_a_window_sized_beside_it.pad
Result
{data 'xs'}
[1,2,3,4,5,6]
{/data}
[{xs page=2, rows=2, negative}{$xs}{/xs}]
[{xs start=2, end=4, negative}{$xs}{/xs}]
[{xs end=3, rows=2, negative}{$xs}{/xs}]


App: regression/framework - Page: options/page_moves_along_by_that_many
PHP
HTML
options/page_moves_along_by_that_many.pad
Result
{data 'n'}
[1,2,3,4,5,6]
{/data}
{n rows=2, page=3}
{$n},
{/n}


App: regression/framework - Page: options/rows_limits_how_many
PHP
HTML
options/rows_limits_how_many.pad
Result
{data 'n'}
[1,2,3,4,5,6]
{/data}
{n rows=2}
{$n},
{/n}


App: regression/framework - Page: tags/a_pager_after_a_cached_paged_tag_pages_its_rows
PHP
tags/a_pager_after_a_cached_paged_tag_pages_its_rows.php
HTML
tags/a_pager_after_a_cached_paged_tag_pages_its_rows.pad
Result
<?php

// The two paged tags are one entry of the option form: the second is a hit, which runs
// no handling of its own rows. vary= keeps a run off an earlier run's copy.

$items = [ [ 'n' => 1 ], [ 'n' => 2 ], [ 'n' => 3 ], [ 'n' => 4 ], [ 'n' => 5 ] ];
$token = uniqid ( '', TRUE );

?>
{items page=2, rows=2, cache=60, vary=$token}{$n} {/items}|{items page=2, rows=2, cache=60, vary=$token}{$n} {/items}|{pager 'items'}{$kind}:{$page} {/pager}


App: regression/framework - Page: tags/chart_treemap_without_names_draws_a_part_per_row
PHP
HTML
tags/chart_treemap_without_names_draws_a_part_per_row.pad
Result
{chart 'treemap', value='kb'}
year,kb
2021,120
2022,340
2023,560
{/chart} {chart 'pack', sequence='fibonacci', rows=5}