我正在使用带有以下设置的Smarty:
$smarty = new Smarty;
$smarty -> caching =3600;
$smarty -> compile_check =true;
$smarty -> compile_dir = 'theme/compile/';
$smarty -> config_dir = 'theme/libs/';
$smarty -> cache_dir = 'theme/cache/';
$smarty -> plugins_dir = 'theme/libs/plugins/';
$smarty->left_delimiter = '{';
$smarty->right_delimiter = '}';
$smarty -> clear_compiled_tpl();我想用这个函数编写一个简单的访客计数器:
function counter() {
$ip = $_SERVER['REMOTE_ADDR'];
$now = time();
$y1 = jgmdate("Y ", $now);
$y1 = (int) $y1;
$m1 = jgmdate("m", $now);
$m1 = (int) $m1;
$d1 = jgmdate("d", $now);
$d1 = (int) $d1;
$result3 = mysql_query("SELECT `times`,`id` FROM `stat_ip` where `IP`='$ip' AND `year`='$y1' AND `month`='$m1' AND `day`='$d1' ;");
unset($n3);
$n3 = (int) mysql_num_rows($result3);
echo $n3;
if ($n3 == 0) {
mysql_query("INSERT INTO `stat_ip` (`id` ,`IP` ,`year` ,`month` ,`day`) VALUES (NULL , '$ip', '$y1', '$m1', '$d1') ;");
} else if ($n3 == 1) {
$row3 = mysql_fetch_array($result3);
$s = (int) $row3['times'] + 1;
mysql_query("UPDATE `stat_ip` SET `times` = '$s' WHERE `id` = '".$row3['id']."' ;");
} else {
echo("error");
}
}一切正常,但是我的查询在这一行中执行了不止一次(可能是所有查询):
mysql_query("UPDATE `stat_ip` SET `times` = '$s' WHERE `id` = '".$row3['id']."' ;") ;我觉得聪明跟我的问题有关!
当我写这段代码时:
$q=$smarty -> fetch('index.tpl');但是,当我将代码更改为:
$q=$smarty -> fetch('index.tpl');
echo $q;或
$smarty -> display('index.tpl');我的查询执行了多次!:(
有关详细信息,请参阅:
发布于 2012-07-17 16:23:09
一个常见的错误是在您的html输出中有一个空的img-tag或script-tag -这会使浏览器重新请求当前页面。
发布于 2012-07-17 02:30:34
为什么要调用$smarty->clear_compiled_tpl();?它确实会删除所有已编译的模板,并在每次调用页面时导致重新编译。删除此行。
您是在哪里以及如何调用函数计数器的?
发布于 2012-07-17 20:44:55
我的问题解决了:
我使用的幻灯片在java脚本代码中有下面这一行:
我在jquery.nivo.slider.js中将src="#“更改为src="”
它现在工作得很好,但是我真的不知道为什么浏览器工作起来很有趣!
谢谢
https://stackoverflow.com/questions/11501621
复制相似问题