我在模板页中用smarty循环出来的数据库的内容,(直接浏览模板页,源代码中有数据库中的内容)
但是查看自动生成的页面源代码中 却没有出现循环的那部分内容?有什么原因会导致这中情况呀???或者说
还有什么方法可以使在数据库中的内容显示在自动生成的页面中(需要循环出来的)

解决方案 »

  1.   

    这是我生成静态页面的代码;<?php
    include('../config.ini.php');
    include('../common/smarty.php');
    include('../common/mysql.php');
    $editor=new Editor;
    $content=$editor->show('content','');
    if(isset($_POST['action']) && $_POST['action']=='add'){
      $title=$_POST['title'];
      $content=$_POST['content'];
      $author=$_POST['author'];
      $time=$_POST['year'].'-'.$_POST['month'].'-'.$_POST['days'];
      $sql="insert into `article`(title,content,author,addtime,hits) values ('$title','$content','$author','$time','0')";
      $res=$db->exec($sql);
      $id=$db->lastInsertId();
      $sqls="select * from `article` where `id`=".$id;
      $ress=$db->getRow($sqls);
      $tpl->assign('res',$ress);
      if(!file_exists($ROOT.'/html')){
        mkdir($ROOT.'/html');
      }
      $open=fopen($ROOT.'/html/article-'.$id.'.html','w');
      $content=$tpl->fetch($ROOT.'/content.html');
      fwrite($open,$content);
      echo "<script>alert('发表成功!');location.href='article.php';</script>";
    }
    $tpl->assign('content',$content);
    $tpl->display('admin/article.html');
    ?>这是要在模板中循环的内容  content.html是模板页if(isset($_POST['action']) && $_POST['action']=='add'){
      $tit=$_POST['tit'];
      $sql="insert into `slselina` (tit) values ('$tit')";
      $res=$db->getRow($sql);
      $sesql="select * from `slselina` order by id desc limit 5";
      $seres=$db->getAll($sesql);
    }
    $tpl->assign('tits',$seres);
    $tpl->fetch($ROOT.'/content.html');
    $tpl->display('admin/slselina.html');
    请指点
      

  2.   


    你既然用smarty 
    那么在后台先取出数据库的数组后,在用foreach循环输出 到html页
    html绑定不就可以了么
      

  3.   

    $tpl->assign('name', $数据库数组);
    html 页面{$name }