Php 使用smarty执行Sql查询的次数超过一次

Php 使用smarty执行Sql查询的次数超过一次,php,mysql,sql-update,smarty,smarty2,Php,Mysql,Sql Update,Smarty,Smarty2,我正在使用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 -> p

我正在使用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");
    }
}
一切正常,但我的查询在此行中执行了多次(可能是所有查询):

我想smarty和我的问题有关

当我编写此代码时:

$q=$smarty -> fetch('index.tpl');
但是,当我将代码更改为:

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

我的查询执行多次!:(

有关更多信息:


为什么要调用$smarty->clear_compiled_tpl();? 它确实会删除所有已编译的模板,并在每次调用页面时导致重新编译。 拆下这条线


您在哪里以及如何调用函数计数器?

为什么要调用$smarty->clear_compiled_tpl();? 它确实会删除所有已编译的模板,并在每次调用页面时导致重新编译。 拆下这条线


您在何处以及如何调用函数计数器?

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

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

我的问题是已解决:

我使用的幻灯片放映有以下java脚本代码行:

我在jquery.nivo.slider.js中将src=“#”更改为src=”“

现在它工作的很好,但是我真的不知道为什么浏览器工作的很有趣

谢谢

我的问题解决了:

我使用的幻灯片放映有以下java脚本代码行:

我在jquery.nivo.slider.js中将src=“#”更改为src=”“

现在它工作的很好,但是我真的不知道为什么浏览器工作的很有趣


谢谢

Smarty只是一个模板引擎,它不应该导致数据库出现问题。您的问题可能在模板引擎之外的某个地方。

Smarty只是一个模板引擎,它不应该导致数据库出现问题。您的问题可能在模板引擎之外的某个地方。

如果确实输出了任何内容你的问题的原因是,它不聪明。你有带过滤器的输出缓冲区吗?或者一些关闭功能?我不明白你的意思。你能给我们看一下索引吗。tpl?如果你的问题是因为实际输出了什么,那就不聪明了。你有带过滤器的输出缓冲区吗?或者一些关闭功能吗?我不明白你的意思你的意思是你能给我们看看index.tpl吗?我已经删除了clear\u compiled\u tpl,不幸的是问题存在了!当我删除$smarty->display('index.tpl')时;没问题!我的程序在Opera中运行正常!!!我的问题似乎与此提示有关:输出中很可能有一个空的img src-或script src-或link href stylesheet属性。浏览器尝试加载相对于当前URL的图像,并再次获取index.php。我如何才能解决此问题:(?我已删除clear\u compiled\u tpl,不幸的是,问题存在!当我删除$smarty->display('index.tpl')时;没问题!我的程序在Opera中运行正常!!!我的问题似乎与此提示有关:输出中很可能有一个空的img src-或script src-或link href stylesheet属性。浏览器尝试加载相对于当前URL的图像,并再次获取index.php。我如何才能解决此问题:(?为什么我不使用smarty时,问题不存在?为什么我不使用smarty时,问题不存在?
$q=$smarty -> fetch('index.tpl');
echo $q;
$smarty -> display('index.tpl');