[求助] 简单运用smarty技术不成功!!

[求助] 简单运用smarty技术不成功!!

功能只是简单的从数据库里读取出数据出来显示
index.php

[复制到剪切板]
CODE:
<?php 
include_once( "include/config_conn.php");
include_once( 
"include/global.func.php" );

//$result -> free();
//$conn -> close();

//引用类文件 
require 'libs/Smarty.class.php'
$smarty = new Smarty
//设置各个目录的路径,这里是安装的重点 
$smarty->template_dir "templates/templates"
$smarty->compile_dir "templates/templates_c"
$smarty->config_dir "templates/config"
$smarty->cache_dir "templates/cache"
$query   "select id,title from article order by id desc Limit 0,6";
$result mysqli_query($conn$query);
$rows mysqli_fetch_array($resultMYSQLI_ASSOC);
$smarty->assign('contacts'$rows);
$smarty->display('index.tpl');
?> ;


index.tpl

[复制到剪切板]
CODE:
<div class="index">
        <
ul>
   {
section name=co loop=$contacts}
             <
li>{$contacts[co].id}</li>           
            {
sectionelse}
             <
li>No items found~!</li>
            {/
section}
     </
ul>
   </
div> ;

运行结果:

[复制到剪切板]
CODE:
<div class="index">
        <
ul>
                <
li></li>           
                         <
li></li>           
                 </
ul>
   </
div> ;

mysqli_fetch_array 是指返回一行啊。这样试试

[复制到剪切板]
CODE:
$query   "select id,title from article order by id desc Limit 0,6";
$result mysqli_query($conn$query);
$rows = array();
while(
$row mysqli_fetch_array($resultMYSQLI_ASSOC)){
    
$rows[] = $row;
} ;


如履薄冰

哈哈,正如你所说~~

搞定。。谢谢哈。。