thinkphp5项目--个人博客(七)
thinkphp5项目--个人博客(七)
项目地址
fry404006308/personalBlog: personalBlog
https://github.com/fry404006308/personalBlog
一、标签部分(thinkphp框架中html中可以直接写原生的php)

视图
这是另一个位置相似的代码,加了span标签便于理解html和php的关系
<span class="writor">标签:
<?php
$arr=explode(',',$articleres['keywords']);
foreach($arr as $k => $v){
echo "<a href='#'>$v</a>";
}
?>
</span>
二、两个常用的string函数str_replace和explode
替换文章关键词中的中文逗号为英文逗号
'keywords'=>str_replace(',', ',', input('keywords')),
以英文逗号来截取文章
$arr=explode(',',$articleres['keywords']);
三、ThinkPHP where的使用
参考手册
普通查询
最简单的数组查询方式如下: $map['name'] = 'thinkphp';
$map['status'] = 1;
// 把查询条件传入查询方法
Db::table('think_user')->where($map)->select();
// 助手函数
db('user')->where($map)->select();
最后生成的SQL语句是
SELECT * FROM think_user WHERE `name`='thinkphp' AND status=1
项目中用处
//相关文章
public function ralate($keywords,$id){
$arr=explode(',',$keywords);
static $ralateres= array();
foreach ($arr as $k => $v) {
//找相似关键词的文章
$map['keywords']=['like','%'.$v.'%'];
//自己相同的文章不能显示在这里,id不能相同
$map['id']=['neq',$id];
$tmp=db('article')->where($map)->order('id desc')->limit(8)->select();
$ralateres=array_merge($ralateres,$tmp);
}
//给$ralateres去重,因为不同关键词匹配的时候可能匹配到重复文章
// array_unique只能做一维的,所以我们用自己写的函数
// $ralateres=arr_unique($ralateres); return $ralateres;
}
四、同类文章推荐

找两篇文章的多个标签中能否有一个相同
//相关文章
public function ralate($keywords,$id){
$arr=explode(',',$keywords);
static $ralateres= array();
foreach ($arr as $k => $v) {
//找相似关键词的文章
$map['keywords']=['like','%'.$v.'%'];
//自己相同的文章不能显示在这里,id不能相同
$map['id']=['neq',$id];
$tmp=db('article')->where($map)->order('id desc')->limit(8)->select();
$ralateres=array_merge($ralateres,$tmp);
}
//给$ralateres去重,因为不同关键词匹配的时候可能匹配到重复文章
// array_unique只能做一维的,所以我们用自己写的函数
// $ralateres=arr_unique($ralateres); return $ralateres;
}
五、使用函数文件

thinkphp5项目--个人博客(七)的更多相关文章
- thinkphp5项目--个人博客(五)
thinkphp5项目--个人博客(五) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- thinkphp5项目--个人博客(八)
thinkphp5项目--个人博客(八) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- thinkphp5项目--个人博客(六)
thinkphp5项目--个人博客(六) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- thinkphp5项目--个人博客(四)
thinkphp5项目--个人博客(四) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- thinkphp5项目--个人博客(三)
thinkphp5项目--个人博客(三) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- thinkphp5项目--个人博客(一)
thinkphp5项目--个人博客(一) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- thinkphp5项目--个人博客(二)
thinkphp5项目--个人博客(二) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- 2015-2016-2 《Java程序设计》项目小组博客
2015-2016-2 <Java程序设计>项目小组博客 1451 完+美 java项目 守望先疯 JavaGroup 07_10_20_22 FromBottomToTop L.G.Su ...
- 团队项目系列博客 —— 在路上(之wampserver 修改根目录以及配置多站点以及修改端口号)
团队项目系列博客 -- 在路上(之wampserver 修改根目录以及配置多站点以及修改端口号) 标签(空格分隔): wampserver php 参考:参考文献1.慕课网.知乎.github 一.w ...
随机推荐
- 一个简单搜索引擎的搭建过程(Solr+Nutch+Hadoop)
最近,因为未来工作的需要,我尝试安装部署了分布式爬虫系统Nutch,并配置了伪分布式的Hadoop来存储爬取的网页结果,用solr来对爬下来的网页进行搜索.我主要通过参考网上的相关资料进行安装部署的. ...
- PatentTips – Java native function calling
BACKGROUND OF INVENTION This invention relates to a system and method for providing a native functio ...
- SQL SERVER-集合操作
内连接 INNER JOIN(等值连接):只显示两个表中联结字段相等的行.这个和用select查询多表是一样的效果,所以很少用到:外连接:LEFT JOIN :以左表为基础,显示左表中的所有 ...
- C#上传文件
QQ:1187362408 欢迎技术交流和学习 关于C#上传文件(产品开发): TODO: 1.文件大小不足500M(web.config配置直接处理) 2,文件大小超过500M(ASP.NET分段读 ...
- QMutex“A mutex must be unlocked in the same thread that locked it”解决(在run里创建对象是不二法宝)
多线程时出现如下警告信息: A mutex must be unlocked in the same thread that locked it: 原因可能有二: 1.创建QMutex不在当前线程: ...
- LeetCode 190. Reverse Bits (算32次即可)
题目: 190. Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 432 ...
- mybatis批量插入、批量更新和批量删除
转载 https://www.jianshu.com/p/041bec8ae6d3
- ActiveMQ学习笔记(16)----Message Dispatch高级特性(二)
1. Optimized Acknowledgetment ActiveMQ缺省支持批量确认消息,由于批量确认会提高性能,如果希望在应用程序中禁止经过优化的确认方式,可以采用以下几种方式: 1. 在C ...
- OSI概述问答
1. 网络中体系结构的七层.四层.五层是怎么回事? OSI(Open System Interconnection)开放系统互连参考模型的七层协议体系结构:概念清楚,理论比较完整,但既复杂又不用 ...
- (WC2018模拟十二)【FJOI2016集训Day7T2】点对游戏
题解: 还好...看懂题目就好做了.(Orzdyh) 首先选择的点是等概率随机的,也就是说每种选择结果的概率都是一样的,所以选择一个点的时候已经选择的点不会有影响,那么就可以直接算出点对个数再求总体的 ...