MySQL遇到经典例子--(遇到就写)

1,一般的搜索只会搜索标题,也有特殊的情况,就是标题和内容一起搜索!

1 -- 模糊搜索只是搜索标题
2 $sql = "select count(*) as sum from publish where pub_title like '%{$keyword}%' or pub_content like '%{$keyword}%'";
3 
4 -- 模糊搜索搜索标题和内容
5 $sql = "select * from publish left join user on pub_owner = user_name where pub_title like '%{$keyword}%' or pub_content like '%{$keyword}%' order by pub_time desc limit $offset, $rowsPerPage";

 2.查询今天的内容

1 // 查询今日帖数
2 // 今日的日期20170916
3 $today_time = date('Y-m-d',time());
4 $today_sql ="select count(*) as sum from (select from_unixtime(pub_time) as t  from publish) as a where  a.t like '%{$today_time}%'";
5 $today_result = my_query($today_sql);
6 $today_row = mysql_fetch_row($today_result);

 3.根据时间戳查询一个表内每一天最新的一条数据

 
posted @ 2017-09-16 08:06  QinXiao.Shou  阅读(268)  评论(0编辑  收藏  举报