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 ...
随机推荐
- 洛谷 P3420 [POI2005]SKA-Piggy Banks
P3420 [POI2005]SKA-Piggy Banks 题目描述 Byteazar the Dragon has NN piggy banks. Each piggy bank can eith ...
- [Puppeteer] Get a Page's Load Time with Puppeteer (window.profermence.timing)
In this lesson we are going to use Google's Puppeteer to gather metrics about a page's load time. We ...
- cocos2d-x-3.3rc2-003 cocos中的引用计数和自己主动释放池
点击打开链接
- 如何用Android studio生成正式签名的APK文件
必须签名之后才可以发布到app商店中. 平时的调试的app都有默认的签名. 下面是生成带签名的APK的步骤: 1. Build 选择 Generate Signed APK 2. 弹出框,第一次选择C ...
- SpringMVC+Spring+Hibernate框架整合原理,作用及使用方法
转自:https://blog.csdn.net/bieleyang/article/details/77862042 SSM框架是spring MVC ,spring和mybatis框架的整合,是标 ...
- [原创]微信小程序 实现 圆环 百分百效果
1.最终效果 2.技术点:a. css3 clip-path , b.根据角度和直边计算另一个直边的长度 3.实现思路: a.3个层(灰色圆形层, 红色圆形层,白色圆形层) ,其中灰色和红色层大小一 ...
- WinForm关于listview的用法介绍
public Form1() { InitializeComponent(); //控件的行为 listView1.Bounds = , ), , ));//相对位置 listView1.View = ...
- 编译Speex生成so库文件(android-speex)
项目中需要用音频格式转换,之前使用VoAacEncoder,部分手机总是莫名崩溃,所以决定不再使用VoAacEncoder,换做Speex来完成格式转换,但是没有找到Speex的库文件,网上介绍的都是 ...
- jQuery学习(一)——jQuery入门
1.jQuery基础 Jquery它是一个库(框架),要想使用它,必须先引入! jquery-1.8.3.js:一般用于学习阶段. jquery-1.8.3.min.js:用于项目使用阶段 官网下载后 ...
- 读取XML字符串到临时表
DECLARE @hdoc int DECLARE @doc xml SET @doc = '<CityValueSet> <CityItem> <CityId>2 ...