[英]MySql query to get results based on timestamp
Here, Im trying to get some details based on the difference between two timestamps ie, there is a modified column which stores a timestamp, and there is created column from another table which also stores a timestamp.在这里,我试图根据两个时间戳之间的差异来获取一些详细信息,即,有一个修改后的列存储时间戳,并且从另一个表创建的列也存储时间戳。 what i need is timestamp(created) between timestamp(modified) and timestamp(current time).我需要的是时间戳(修改)和时间戳(当前时间)之间的时间戳(创建)。 Plzz help请帮忙
Error Number: 1054错误号:1054
Unknown column 'Array' in 'where clause' 'where 子句'中的未知列'Array'
select * from campaigns where created BETWEEN timestamp(Array) AND timestamp(CURRENT_TIMESTAMP()) select * 来自在时间戳(数组)和时间戳(CURRENT_TIMESTAMP())之间创建的活动
Filename: models/Notification_model.php文件名:models/Notification_model.php
Line Number: 11行号:11
<?php
class Notification_model extends CI_Model
{
public function notifications()
{
$q1="select modified from influencer where influencerid=".$this->session->userdata('id')."";
$query1 = $this->db->query($q1);
$this->session->set_userdata('modified_time',$query1->result());
$q="select * from campaigns where created BETWEEN timestamp(".$this->session->userdata('modified_time').") AND timestamp(CURRENT_TIMESTAMP())";
$query = $this->db->query($q);
if($query->num_rows()>0){
return $query->result();
}
}
}
?>
Your $query1->result()
is returning an array, you should take the first row, and the first column ( updated
):您的$query1->result()
正在返回一个数组,您应该取第一行和第一列( updated
):
$modified_time = $query1->result()[0][0];
Moreover, it's a very bad idea and a big security issue to do this:此外,这样做是一个非常糟糕的主意和一个很大的安全问题:
$q1="select modified from influencer where influencerid=".$this->session->userdata('id')."";
You can be hacked with SQL injection.您可能会被 SQL 注入攻击。 For example, if I define the ID to: 1; UPDATE users SET is_admin = 1
例如,如果我将 ID 定义为: 1; UPDATE users SET is_admin = 1
1; UPDATE users SET is_admin = 1
, the SQL request becomes: select modified from influencer where influencerid=1; UPDATE users SET is_admin = 1
1; UPDATE users SET is_admin = 1
,SQL 请求变为: select modified from influencer where influencerid=1; UPDATE users SET is_admin = 1
select modified from influencer where influencerid=1; UPDATE users SET is_admin = 1
, and I'm admin of your system. select modified from influencer where influencerid=1; UPDATE users SET is_admin = 1
,我是您系统的管理员。
You should prepare your statements to prevent this hack:您应该准备好您的陈述以防止这种黑客攻击:
$query = $this->db->prepare("select modified from influencer where influencerid = :id");
$query->bindParam(':id', $this->session->userdata('id'));
$query->execute();
More info here: https://www.php.net/manual/en/pdo.prepared-statements.php更多信息在这里: https://www.php.net/manual/en/pdo.prepared-statements.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.