Smarty Template Engine fetching single row from database and using the fields

329 views Asked by At

I am new to smarty and stepped into a problem. As per their manual if I fetch data from the database and want to display it in a loop then I can easily use the foreach function but here I want to transfer the values of single row and use them on the tpl page using if else. How can I transfer the value and use them without using foreach for a single row?

My server side code

$verify = $pdo->prepare("SELECT ver_code, ver_validity FROM verification WHERE ver_user = :user");
$verify-> bindValue(':user', $_GET['user']);
$verify-> execute();
//   $vf = $verify->fetch();
//   $code = $vf['ver_code'];
//   $expiry = $vf['ver_validity'];

$smarty->assign('verify', $vf);

$smarty->display('reset.tpl');

I want to send the values coming from database to the presentation code and use them using the if else statement. Please help me on solving this issue.

1

There are 1 answers

0
JochenJung On

Fetch one single row:

$vf = $verify->fetch();

Assign it to Smarty variable:

$smarty->assign('verify', $vf);

Use it in the Smarty template like:

{$verify.ver_code}
{$verify.ver_validity}

Inside an if statement:

{if $verify.ver_code eq "abcdefg"}

Hope this helps.