Reference - Select options - union


App: classicModels - Page: options
PHP
HTML
options.pad
Result
<p>where: {offices where="country = 'USA'", order='officeCode'}{$officeCode},{/offices}</p>
<p>distinct: {offices distinct, fields='country', order='country'}{$country},{/offices}</p>
<p>distinctrow: {offices distinctrow, fields='country', order='country'}{$country},{/offices}</p>
<p>group: {payments fields='customerNumber, count(*) as cnt', group='customerNumber', having='cnt > 9', order='customerNumber'}{$customerNumber}={$cnt},{/payments}</p>
<p>rollup: {offices key='', fields='count(*) as cnt', group='country', rollup}{last@offices}{$cnt}{/last@offices}{/offices}</p>
<p>db: {sales db='employees', where="jobTitle = 'President'"}{$lastName}{/sales}</p>
<p>key: {offices key='city', where="country = 'USA'"}{$city},{/offices}</p>
<p>union: {offices where="officeCode = 1", union='offices'}{$officeCode},{/offices}</p>
<p>join: {employees join='offices on employees.officeCode = offices.officeCode', where="offices.city = 'Boston'", order='lastName'}{$lastName},{/employees}</p>
<p>htmlAttrJson: {select:offices htmlAttrJson='record', fields='officeCode', where="officeCode = 1"}</p>


App: regression/pages - Page: select/demo/options
PHP
select/demo/options.php
HTML
select/demo/options.pad
Result
<?php

// The options a declared select table takes on the tag itself: each section of the .pad
// half names one, over the four-row staff table of the demo database.

$padSelect ['staffSel'] = [ 'db' => 'staff', 'key' => 'name' ];
$padSelect ['elsewhere'] = [ 'key' => 'name' ];
$padSelect ['staffJim'] = [ 'db' => 'staff', 'where' => "name = 'jim'" ];
$padSelect ['staffRaw'] = [ 'db' => 'staff' ];

?>
where: [{staffSel where="salary >= 2000", order="salary"}{$name} {/staffSel}]
order: [{staffSel order="salary desc", fields="name"}{$name} {/staffSel}]
fields: [{staffSel fields="name, bonus", where="name = 'bob'"}{$name}/{$bonus}{/staffSel}]
group: [{staffSel fields="count(*) as heads", group="floor(salary / 2000)", order="heads"}{$heads} {/staffSel}]
having: [{staffSel fields="salary + bonus as total", group="total", having="total > 2500", order="total"}{$total} {/staffSel}]
rollup: [{staffRaw fields="sum(salary) as pay", group="name", rollup}{$pay} {/staffRaw}]
distinctrow: [{staffSel fields="floor(salary / 2000) as band", distinctrow, order="band"}{$band} {/staffSel}]
db: [{elsewhere db='staff', where="name = 'jim'"}{$name}/{$phone}{/elsewhere}]
union: [{staffSel where="name = 'bob'", union='staffJim', order="name"}{$name} {/staffSel}]


App: regression/pages - Page: select/demo/union
PHP
select/demo/union.php
HTML
select/demo/union.pad
Result
<?php

$padSelect
['union1'] = [ 'base' => 'table1', ] ;
$padSelect ['union12'] = [ 'base' => 'table1', 'union' => 'table2' ] ;
$padSelect ['union1234'] = [ 'base' => 'table1', 'union' => [ 'table2', 'table3', 'table4' ] ] ;

?>
<h1>Union demo</h1>

<h2>1</h2>

<table border=1>
{union1}
<tr>
<td>{$key}</td>
<td>{$text}</td>
</tr>
{/union1}
</table>

<h2>1 2</h2>

<table border=1>
{union12}
<tr>
<td>{$key}</td>
<td>{$text}</td>
</tr>
{/union12}
</table>

<h2>1 2 3 4</h2>

<table border=1>
{union1234}
<tr>
<td>{$key}</td>
<td>{$text}</td>
</tr>
{/union1234}
</table>