|
网站根目录smarty
|--smarty
|--class
|--Smarty.class.php
|--Config_File.class.php
|--Smarty_Compiler.class.php
|--plugins
|--internals
|--configs
|--includes
|--templates
|--index.tpl
|--templates
|--cache
|--index.php
|--news.php
|--main.php
index.php
<?php
//新闻显示主页
require "main.php";
//define("NUM",5);
$db = mysql_connect("localhost","dudu","128307111");
mysql_select_db("news",$db) or die;
//国内新闻部分
$strQuery = "SELECT vcNewsTitle , iNewsID FROM mz_news_ch ORDER BY iNewsID DESC";
$result = mysql_query($strQuery) or die;
$i=NUM;
while(($rows = mysql_fetch_array($result)) && $i > 0)
{
$array[] = array("NewsID" => substr($rows["iNewsID"],0,40),"NewsTitle" => substr($rows["vcNewsTitle"],0,40));
$i--;
}
$smarty->assign("News_CH",$array);
unset($array);
mysql_free_result();
//国际新闻部分
$strQuery = "SELECT vcNewsTitle , iNewsID FROM mz_news_in ORDER BY iNewsID DESC";
$result = mysql_query($strQuery);
$i=NUM;
while(($rows = mysql_fetch_array($result)) && $i > 0)
{
$array[] = array("NewsID" => substr($rows["iNewsID"],0,40),"NewsTitle" => substr($rows["vcNewsTitle"],0,40));
$i--;
}
$smarty->assign("News_IN",$array);
unset($array);
mysql_free_result();
//娱乐新闻部分$strQuery = "SELECT vcNewsTitle , iNewsID FROM mz_news_mu ORDER BY iNewsID DESC";
$result = mysql_query($strQuery);
$i=NUM;
while(($rows = mysql_fetch_array($result)) && $i > 0)
{
$array[] = array("NewsID" => substr($rows["iNewsID"],0,40),"NewsTitle" => substr($rows["vcNewsTitle"],0,40));
$i--;
}
$smarty->assign("News_MU",$array);
unset($array);
mysql_free_result();
mysql_close($db);
$smarty->display("index.html");
?>
main.php
<?php
require('class/Smarty.class.php');
define('__SITE_ROOT', 'd:/httproot/smarty');
$smarty = new Smarty();
$smarty->templates_dir = __SITE_ROOT."/templates/";
$smarty->compile_dir = __SITE_ROOT."/templates_c/";
$smarty->config_dir = __SITE_ROOT . "/configs/";
$smarty->cache_dir = __SITE_ROOT."/cache/";
$smarty->cache_lifetime = 60*60*24;
$smarty->caching = ture;
$smarty->left_delimiter = "<{";
$smarty->right_delimiter = "}>";
?>
模版文件 index.tpl
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新闻主页</title>
</head>
<body>
<table width="100%">
<tr>
<td valign="top" width="295" height="115" bgcolor="#b9e9ff">
<{section name=loop loop=$News_CH}>
<li><a href="news.php?type=1&id=<{News_CH[loop].NewsID}>"><{NewsTitle}></a>
<{/section}>
</td>
</tr>
</table>
<table width="100%">
<tr>
<td valign="top" width="295" height="115" bgcolor="#b9e9ff">
<{section name=loop loop=$News_IN}>
<li><a href="news.php?type=2&id=<{News_IN[loop].NewsID}>"><{NewsTitle}></a>
<{/section}>
</td>
</tr>
</table>
<table width="100%">
<tr>
<td valign="top" width="295" height="115" bgcolor="#b9e9ff">
<{section name=loop loop=$News_MU}>
<li><a href="news.php?type=3&id=<{News_MU[loop].NewsID}>"><{NewsTitle}></a>
<{/section}></td>
</tr>
</table>
</body>
</html>
求救:无法调试出页面,浏览器空白,甚至把index.php文件故意改成错误也不能提示,还是空白。。。。急……
后来重装apache服务器后,调试出错:
Fatal error: Smarty error: [in index.html line 11]: syntax error: unrecognized tag: News_CH[loop].NewsID (Smarty_Compiler.class.php, line 439) in D:\httproot\smarty\class\Smarty.class.php on line 1095
顺便问一下,mysql4.0.*是不是不支持mysql_free_result()
求救…………
[ 本帖最后由 x_man 于 2006-11-10 21:50 编辑 ] |
|