{check}
Asks the application database whether a row exists, and renders its content only when one does.
Syntax
{check "table where ..."} ... {/check}
{check "users where email='x@y.z'"} ... @else@ ... {/check}
Parameters
-
condition -
A table and a WHERE clause -
"users where active=1". No* from: CHECK takes the bare table.
Options
-
name -
In the designer preview (
&padSample) the sample's value of that name answers, true or false, instead of the database.
Description
{check "..."} asks the database whether a row exists and answers TRUE or FALSE: on a hit the content renders, otherwise the @else@ branch does (or nothing). It is the template form of db ( "CHECK ..." ), and CHECK has a form of its own: a bare table followed by a WHERE clause - {check "orders where status='open'"}, never {check "* from orders ..."}.
Nothing of the row is read, so no field of it is available in the content - use {record} when the row itself is wanted. For a test on a value that is already in a variable, {if} is the tag.
As with the other database tags, a request value belongs in a placeholder in PHP: $taken = db ( "CHECK users WHERE email='{0}'", [ $email ] ); and then {if $taken}.
Examples
Does it exist?
A table and a WHERE clause - the content on a hit, @else@ otherwise.
{check "orders where status='open'"}
<p>There is work waiting.</p>
@else@
<p>All orders are done.</p>
{/check}
The same from PHP
With a request value the check belongs in PHP, through a placeholder.
{# signup.php: $taken = db ( "CHECK users WHERE email='{0}'", [ $email ] ); #}
{if $taken}
<p>That address already has an account.</p>
{/if}
See also
- {record} Runs a SQL query on the application database and renders its content with the first row's columns as fields.
- {field} Runs a SQL query on the application database and prints the single value it answers.
- {array} Runs a SQL query on the application database and repeats its content once per row.
- {if} Renders its content only when a condition holds, with elseif and else branches.