关于where like
$s="%".addcslashes($uid, '%_')."%";return DB::fetch_all('select * from %t where uid like %s limit %d,%d',array($this->_table,$s,$start,$perpage));
上面的一段代码 可以查询出 关于UID是某位数字的用户全部信息
请问下 在这段代码里加点什么 可以是调用出来的信息 按信息ID的从大到小“desc”排序?
回复讨论(解决方案)
$s="%".addcslashes($uid, '%_')."%";
return DB::fetch_all('select * from %t where uid like %s order by id desc limit %d,%d',array($this->_table,$s,$start,$perpage));
order by id desc
$s="%".addcslashes($uid, '%_')."%";
return DB::fetch_all('select * from %t where uid like %s order by id desc limit %d,%d',array($this->_table,$s,$start,$perpage));
你的回答是正确的。感谢。
我还想追问下 在这段代码里 怎么添加排除语法? 比如uid >1
$s="%".addcslashes($uid, '%_')."%";
return DB::fetch_all('select * from %t where uid like %s and uid>1 order by id desc limit %d,%d',array($this->_table,$s,$start,$perpage));
$s="%".addcslashes($uid, '%_')."%";
return DB::fetch_all('select * from %t where uid like %s and uid>1 order by id desc limit %d,%d',array($this->_table,$s,$start,$perpage));
最后个问题 还是关于这个的
怎么在这段代码里 添加多运算的排除语法?
比如 发布日期变量为 time 有效期变量为day 当前时间变量为STAMP
怎么排除time+86400*day > STAMP 把这个运算加入里面?
$s="%".addcslashes($uid, '%_')."%";
return DB::fetch_all('select * from %t where uid like %s and uid>1 and time+86400*day>STAMP order by id desc limit %d,%d',array($this->_table,$s,$start,$perpage));
$s="%".addcslashes($uid, '%_')."%";
return DB::fetch_all('select * from %t where uid like %s and uid>1 and time+86400*day>STAMP order by id desc limit %d,%d',array($this->_table,$s,$start,$perpage));
但是STAMP 是当前时间戳的时间 数据库中并未录入 不能成立啊。。
上一篇: oracle提高查询效率