Use following snippets in a PROLOG section of a template or inside a template

Fetch single value to a variable

$uid = Select("enflw FROM enpn2persons WHERE enpnw = ? LIMIT 1", [$CURRENT_USER])->fetchColumn();

Fetch all fields of a single record

$record = Select('enrel_taskw as taskid, a.enrel_taskw.enrel_typew.enf_exp_cntw as cm FROM enrf_stages WHERE a.syrecordidw=?',[$id])->fetch();
echo $record->taskid;
echo $record->cm;

Fetch all records into an array

foreach( Select("syrecordidw, enf_snamew FROM enacademic_degrees WHERE syrecordidw<>?",['000000000000000000000000']) as $val) {
    $degrees[$val->syrecordidw] = $val->enf_snamew;

Update a record

$countUpdated = Update("people WHERE id = ?", [$val1],
"field1" => $val2,
"field2" => $val3,
"field3:SUBSTR(?,1,2)" => "some text"  // equivalent to fields3 = SUBSTR("some text", 1, 2)


.= means a value for an empty choice to be sent to the server and visible inside a control. If you want to rewrite the value sent to the server, you should define a info section, where you may define the value to be sent to the server instead of previously defined value.

  -Voennyjj_bilet000000000=Военный билет

Expression as a chosen value

expr field with CHOOSE attribute will be used in a set of field of chooser. Remember, you may define expressions with ='expression' syntax

TABLE enrf_areas (
syrecordidw CHAR(24) PK 'ID' HIDDEN
, enf_codew VARCHAR 'Код' ORDER(1) SEARCH1*='/([0-9]+)/'
, enf_namew VARCHAR 'Наименование' REQUIRED SEARCH2*='/(.*)/'
, expr VARCHAR 'Expression caption' =(=S:CONCAT( $a.enf_codew, ' ', $a.enf_namew):S=) CHOOSE
, ID: (=S: CONCAT( $a.enf_codew, ' ', $a.enf_namew) :S=)
, DEFAULT_FILTER: (=F: syrecordidw<>'000000000000000000000000' :F=)
, ZERO_RECORD: '000000000000000000000000'


Common rules

Each control must be inside a container with cmd attribute with correct crud url.

Choose a value for a relation with a menu of prefetched data

<a fctl tag=A name="enf_academic_degreew">
<menu mctl>
  [[foreach($degrees as $id=>$value){]]<li value-patch="[[$id]]">[[$value]]</li>[[}]]
  <li value-patch="000000000000000000000000" rt="" empty></li>

Choose a value for a relation with a menu opened by a constant URI

<a tag=A fctl name="enrel_orgw" maxlength=0 rid="[[$org.a.enrel_orgw]]" onclick="setWithMenu(this)" required>
<dl mctl ref=Y>'/site/user/organizations.choose.php.t?add_empty=Y'</dl>


Set an attribute into a tag

Writes text into span attributes if $user.a.syf_userfilew is not empty.

[[$@span $user.a.syf_userfilew?'':'text']]

Set up arguments to SELECT statement

If you have only single SELECT statement, use ~: ending in conjunction with MAIN - directive. Due {CMD} we got a crud link for CRUD operations.

[[PROLOG $p1='12345'; $p2='6789'; ]]
[[MAIN -]]
  [[@div $record : SELECT * FROM T WHERE F1=? AND F2=? ~: [$p1, $p2] ]]
  [[cmd@div $record.{CMD}]]


If you have nested SELECT statements, you don't have to use MAIN.

[[PROLOG $p1='12345'; $p2='6789'; ]]
  [[@div $record : SELECT * FROM T WHERE F1=? AND F2=? ~: [$p1, $p2] ]]
  [[@span $sun of $record : SELECT * FROM Z WHERE F1=? AND F2=? ~: [$p1, $p2] ]]

Other stuff

<table swift label="Коды фонда" list>
[[@tr $area of $user : SAMPLE AND SELECT * FROM enrf_person_areas WHERE enrel_personw = ext.syrecordidw LIMIT ALL]]
[[cmd@tr $area.{CMD a.syrecordidw}]]
[[$@tr $area.{SAMPLE}]]
[[auto-key@tr "syrecordidw"]]
<button del type="button" onclick="doDelete(this, 'удалить?')"></button>
<a fctl tag=A name="enrel_areaw" main_rel check_unique rid="[[$area.a.enrel_areaw]]">[[$area.a.enrel_areaw._id_]]</a>
<tfoot><tr><td colspan=2>
<button add=suspend type=button onclick="setWithMenu(this)" ></button>
<dl mctl ref="EP">'/site/user/rf_areas.choose.php.t{{areaFilter(this)}}'</dl>