gpt4 book ai didi

php - Sql 查询执行超过 smarty 的时间

转载 作者:太空宇宙 更新时间:2023-11-03 11:06:39 24 4
gpt4 key购买 nike

我正在使用具有以下设置的 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']."' ;") ;

我认为 smarty 与我的问题有关!

当我写这段代码时:

$q=$smarty -> fetch('index.tpl');

查询执行了 1 次,但是当我将代码更改为:

$q=$smarty -> fetch('index.tpl');
echo $q;

$smarty -> display('index.tpl');

我的查询执行了不止一次!:(

更多信息:

http://www.smarty.net/forums/viewtopic.php?p=81161

最佳答案

一个常见的错误是在您的 html 输出中有一个空的 img-tag 或 script-tag - 这会使浏览器重新请求当前页面。

关于php - Sql 查询执行超过 smarty 的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11501621/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com