关于php mysql查询问题
其中$time1和$time2都是字符串(2015-05-06)类型的,riqi是数据库中的字段也是字符串类型(2015-05-06),上面那段代码出问题了应该怎么改,双...
其中$time1和$time2都是字符串(2015-05-06)类型的 ,riqi是数据库中的字段 也是字符串类型(2015-05-06),上面那段代码出问题了 应该怎么改,双引号怎么加
$sql="select *from think_kaoqin WHERE(1=1)"; if(!empty($uid)) { $sql .=" and uid= ".$uid; } if(!empty($time1) && empty($time2)) { $sql .=" and riqi >= ".$time1; } if (!empty($time2) &&empty($time1)) { $sql .=" and riqi <= ".$time2; } if (!empty($time1) && !empty($time2)) { $sql .=" and riqi >= ".$time1." and riqi <=".$time2; } $this->info=M('kaoqin')->query($sql); 展开
$sql="select *from think_kaoqin WHERE(1=1)"; if(!empty($uid)) { $sql .=" and uid= ".$uid; } if(!empty($time1) && empty($time2)) { $sql .=" and riqi >= ".$time1; } if (!empty($time2) &&empty($time1)) { $sql .=" and riqi <= ".$time2; } if (!empty($time1) && !empty($time2)) { $sql .=" and riqi >= ".$time1." and riqi <=".$time2; } $this->info=M('kaoqin')->query($sql); 展开
1个回答
展开全部
if(!empty($uid))
{
$sql .=" and uid= ".$uid;
}
if(!empty($time1) && empty($time2))
{
$sql .=" and riqi >= '".$time1."'";
}
if (!empty($time2) &&empty($time1)) {
$sql .=" and riqi <= '".$time2."'";
}
if (!empty($time1) && !empty($time2)) {
$sql .=" and riqi >= '".$time1."' and riqi <='".$time2."'";
}
$this->info=M('kaoqin')->query($sql);
{
$sql .=" and uid= ".$uid;
}
if(!empty($time1) && empty($time2))
{
$sql .=" and riqi >= '".$time1."'";
}
if (!empty($time2) &&empty($time1)) {
$sql .=" and riqi <= '".$time2."'";
}
if (!empty($time1) && !empty($time2)) {
$sql .=" and riqi >= '".$time1."' and riqi <='".$time2."'";
}
$this->info=M('kaoqin')->query($sql);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询