douhan0562 2018-07-10 20:21
浏览 58

Smarty Template Engine从数据库中获取单行并使用这些字段

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条回答 默认 最新

  • dongyou4411 2018-07-16 06:43
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图