On line guide/help

You are on page 32 of the online help. Navigate sequentially through the guide pages or search for a topic of interest to you.

Index Prev. Next

Data placeholder

Using data through variables or database fields

A placeholder is the name of a variable or field returned by a database query or view, enclosed in curly braces. For example:

{MY_VAR_NAME}
{dataset_name.field_name}

It's good practice to write variable names in CAPITALS and database field names in lowercase. This makes it easy to identify the placeholder type, but this is a convention everyone is free to follow or not.

To dynamically replace a variable's value with a value from PHP code, use the SetVar method, for example:

$msg = 'Current date and time is ' . date('Y-m-d h:n:s');
$report->SetVar('HELLO_MESSAGE', $msg);

The function's first parameter is the variable name, written exactly as it appears in the XML template, without the curly braces. The second parameter is the value to use to replace the placeholder.

If there is a mismatch between the variable name defined in the PHP code and the one defined in the XML template, the placeholder in the template remains unchanged. Therefore, all placeholders that are not replaced with data should be checked.

Using placeholders with a dataset

Using a data provider, you can read all the records returned by queries (datasets). The string identifying the dataset, followed by the period ('.') character and the field name, forms the placeholder name to be used in the XML template.

Example PHP code that creates and assigns a data provider

To process all records, you need to use a section element, specifying the key of the dataset to be used with the id element. In the example below, a page is created for each record in the dataset. In every page the color code and its description are printed in a box.

Sample XML code using a dataset