然后我想在SQL中引用这个 $acc_time 怎么写?
附:我的代码
=======================================================
<?php
//基本设置
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "root";
$mysql_database = "mytest";
$ip_addr = getenv("REMOTE_ADDR");
$acc_time = date("YmdHis");
$conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password );
mysql_select_db($mysql_database,$conn);
$result = mysql_query("SELECT INT($acc_time) - `at_time` FROM `counter` WHERE `name` = 'page1' AND `ip_addr` = '$ip_addr' ORDER BY INT($acc_time) - `at_time` ASC");
【主要是上边这一句,我想用现在的来访时间$acc_time 】
【减去数据库存储的at_time时间,求得一个差,怎么写都写不出来!】
4 个解决方案
#1
解决了:
我是如此写得:
$result = mysql_query("SELECT ($acc_time) - `at_time` FROM `counter` WHERE `name` = 'page1' AND `ip_addr` = '$ip_addr' ORDER BY ($acc_time) - `at_time` ASC");
不知道这样有没有什么问题,请高手指教!
我是如此写得:
$result = mysql_query("SELECT ($acc_time) - `at_time` FROM `counter` WHERE `name` = 'page1' AND `ip_addr` = '$ip_addr' ORDER BY ($acc_time) - `at_time` ASC");
不知道这样有没有什么问题,请高手指教!
#2
附计数器完整代码
================
<?php
//基本设置
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "root";
$mysql_database = "mytest";
$ip_addr = getenv("REMOTE_ADDR");
$acc_time = date("YmdHis");
//判断时间间隔
$conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password );
mysql_select_db($mysql_database,$conn);
$result = mysql_query("SELECT $acc_time - `at_time` FROM `counter` WHERE `name` = 'page1' AND `ip_addr` = '$ip_addr' ORDER BY $acc_time - `at_time` ASC");
$row=mysql_fetch_row($result);
$timeout = $row[0]; //判断时间间隔结束
mysql_free_result($result);
if ($timeout > 5 )
{
$conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password );
$sql = "INSERT INTO `counter` ( `name` , `ip_addr` , `at_time` , `new` ) VALUES ('page1','$ip_addr','$acc_time','1');";
mysql_select_db($mysql_database,$conn);
$result = mysql_query($sql);
}
//页面1显示部分
$result=mysql_query( "SELECT COUNT(*) FROM `counter` WHERE `name` = 'page1'");
$row=mysql_fetch_row($result);
//print_r($row);
$page1=$row[0];
mysql_free_result($result);
//页面2显示部分
$result=mysql_query( "SELECT COUNT(*) FROM `counter` WHERE `name` = 'page2'");
$row=mysql_fetch_row($result);
//print_r($row);
$page2=$row[0];
mysql_free_result($result);
//图形计数开始
for($j=0; $j<strlen($page1); $j++)
{
//echo $page1;
//echo "<br>";
//echo $j;
$digi = substr($page1,$j,1);
$page1_pic = $page1_pic . '<img border="0" src="digits/eggs/'.$digi.'.gif" width="15" height="20">';
}
?>
<br>页面1访问计数:<?php echo $page1_pic;?>
<br>页面2访问计数:<?php echo $page2_pic;?>
================
<?php
//基本设置
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "root";
$mysql_database = "mytest";
$ip_addr = getenv("REMOTE_ADDR");
$acc_time = date("YmdHis");
//判断时间间隔
$conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password );
mysql_select_db($mysql_database,$conn);
$result = mysql_query("SELECT $acc_time - `at_time` FROM `counter` WHERE `name` = 'page1' AND `ip_addr` = '$ip_addr' ORDER BY $acc_time - `at_time` ASC");
$row=mysql_fetch_row($result);
$timeout = $row[0]; //判断时间间隔结束
mysql_free_result($result);
if ($timeout > 5 )
{
$conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password );
$sql = "INSERT INTO `counter` ( `name` , `ip_addr` , `at_time` , `new` ) VALUES ('page1','$ip_addr','$acc_time','1');";
mysql_select_db($mysql_database,$conn);
$result = mysql_query($sql);
}
//页面1显示部分
$result=mysql_query( "SELECT COUNT(*) FROM `counter` WHERE `name` = 'page1'");
$row=mysql_fetch_row($result);
//print_r($row);
$page1=$row[0];
mysql_free_result($result);
//页面2显示部分
$result=mysql_query( "SELECT COUNT(*) FROM `counter` WHERE `name` = 'page2'");
$row=mysql_fetch_row($result);
//print_r($row);
$page2=$row[0];
mysql_free_result($result);
//图形计数开始
for($j=0; $j<strlen($page1); $j++)
{
//echo $page1;
//echo "<br>";
//echo $j;
$digi = substr($page1,$j,1);
$page1_pic = $page1_pic . '<img border="0" src="digits/eggs/'.$digi.'.gif" width="15" height="20">';
}
?>
<br>页面1访问计数:<?php echo $page1_pic;?>
<br>页面2访问计数:<?php echo $page2_pic;?>
#3
good
#4
SELECT * FROM `counter` WHERE `name` = 'page1' AND `ip_addr` = '$ip_addr' and TIME_TO_SEC($acc_time) - TIME_TO_SEC(at_time)>5
#1
解决了:
我是如此写得:
$result = mysql_query("SELECT ($acc_time) - `at_time` FROM `counter` WHERE `name` = 'page1' AND `ip_addr` = '$ip_addr' ORDER BY ($acc_time) - `at_time` ASC");
不知道这样有没有什么问题,请高手指教!
我是如此写得:
$result = mysql_query("SELECT ($acc_time) - `at_time` FROM `counter` WHERE `name` = 'page1' AND `ip_addr` = '$ip_addr' ORDER BY ($acc_time) - `at_time` ASC");
不知道这样有没有什么问题,请高手指教!
#2
附计数器完整代码
================
<?php
//基本设置
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "root";
$mysql_database = "mytest";
$ip_addr = getenv("REMOTE_ADDR");
$acc_time = date("YmdHis");
//判断时间间隔
$conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password );
mysql_select_db($mysql_database,$conn);
$result = mysql_query("SELECT $acc_time - `at_time` FROM `counter` WHERE `name` = 'page1' AND `ip_addr` = '$ip_addr' ORDER BY $acc_time - `at_time` ASC");
$row=mysql_fetch_row($result);
$timeout = $row[0]; //判断时间间隔结束
mysql_free_result($result);
if ($timeout > 5 )
{
$conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password );
$sql = "INSERT INTO `counter` ( `name` , `ip_addr` , `at_time` , `new` ) VALUES ('page1','$ip_addr','$acc_time','1');";
mysql_select_db($mysql_database,$conn);
$result = mysql_query($sql);
}
//页面1显示部分
$result=mysql_query( "SELECT COUNT(*) FROM `counter` WHERE `name` = 'page1'");
$row=mysql_fetch_row($result);
//print_r($row);
$page1=$row[0];
mysql_free_result($result);
//页面2显示部分
$result=mysql_query( "SELECT COUNT(*) FROM `counter` WHERE `name` = 'page2'");
$row=mysql_fetch_row($result);
//print_r($row);
$page2=$row[0];
mysql_free_result($result);
//图形计数开始
for($j=0; $j<strlen($page1); $j++)
{
//echo $page1;
//echo "<br>";
//echo $j;
$digi = substr($page1,$j,1);
$page1_pic = $page1_pic . '<img border="0" src="digits/eggs/'.$digi.'.gif" width="15" height="20">';
}
?>
<br>页面1访问计数:<?php echo $page1_pic;?>
<br>页面2访问计数:<?php echo $page2_pic;?>
================
<?php
//基本设置
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "root";
$mysql_database = "mytest";
$ip_addr = getenv("REMOTE_ADDR");
$acc_time = date("YmdHis");
//判断时间间隔
$conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password );
mysql_select_db($mysql_database,$conn);
$result = mysql_query("SELECT $acc_time - `at_time` FROM `counter` WHERE `name` = 'page1' AND `ip_addr` = '$ip_addr' ORDER BY $acc_time - `at_time` ASC");
$row=mysql_fetch_row($result);
$timeout = $row[0]; //判断时间间隔结束
mysql_free_result($result);
if ($timeout > 5 )
{
$conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password );
$sql = "INSERT INTO `counter` ( `name` , `ip_addr` , `at_time` , `new` ) VALUES ('page1','$ip_addr','$acc_time','1');";
mysql_select_db($mysql_database,$conn);
$result = mysql_query($sql);
}
//页面1显示部分
$result=mysql_query( "SELECT COUNT(*) FROM `counter` WHERE `name` = 'page1'");
$row=mysql_fetch_row($result);
//print_r($row);
$page1=$row[0];
mysql_free_result($result);
//页面2显示部分
$result=mysql_query( "SELECT COUNT(*) FROM `counter` WHERE `name` = 'page2'");
$row=mysql_fetch_row($result);
//print_r($row);
$page2=$row[0];
mysql_free_result($result);
//图形计数开始
for($j=0; $j<strlen($page1); $j++)
{
//echo $page1;
//echo "<br>";
//echo $j;
$digi = substr($page1,$j,1);
$page1_pic = $page1_pic . '<img border="0" src="digits/eggs/'.$digi.'.gif" width="15" height="20">';
}
?>
<br>页面1访问计数:<?php echo $page1_pic;?>
<br>页面2访问计数:<?php echo $page2_pic;?>
#3
good
#4
SELECT * FROM `counter` WHERE `name` = 'page1' AND `ip_addr` = '$ip_addr' and TIME_TO_SEC($acc_time) - TIME_TO_SEC(at_time)>5