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项目--个人博客(七)的更多相关文章

  1. thinkphp5项目--个人博客(五)

    thinkphp5项目--个人博客(五) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  2. thinkphp5项目--个人博客(八)

    thinkphp5项目--个人博客(八) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  3. thinkphp5项目--个人博客(六)

    thinkphp5项目--个人博客(六) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  4. thinkphp5项目--个人博客(四)

    thinkphp5项目--个人博客(四) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  5. thinkphp5项目--个人博客(三)

    thinkphp5项目--个人博客(三) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  6. thinkphp5项目--个人博客(一)

    thinkphp5项目--个人博客(一) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  7. thinkphp5项目--个人博客(二)

    thinkphp5项目--个人博客(二) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  8. 2015-2016-2 《Java程序设计》项目小组博客

    2015-2016-2 <Java程序设计>项目小组博客 1451 完+美 java项目 守望先疯 JavaGroup 07_10_20_22 FromBottomToTop L.G.Su ...

  9. 团队项目系列博客 —— 在路上(之wampserver 修改根目录以及配置多站点以及修改端口号)

    团队项目系列博客 -- 在路上(之wampserver 修改根目录以及配置多站点以及修改端口号) 标签(空格分隔): wampserver php 参考:参考文献1.慕课网.知乎.github 一.w ...

随机推荐

  1. C/C++ Quick Sort Algorithm

    本系列文章由 @YhL_Leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50255069 快速排序算法,由C.A. ...

  2. oracle实现自增id

    --oracle实现自增id --创建一张T_StudentInfo表 create table T_StudentInfo ( "id" integer not null pri ...

  3. Medium上的文章

    Welcome to Medium, a place to read, write, and interact with the stories that matter most to you. 网站 ...

  4. python 3.x 学习笔记10 (析构函数and继承)

    1.类变量的用途:大家公用的属性,节省开销(内存) 2.析构函数 在实例释放和销毁的时候执行的,通常用于做一些收尾工作,如关闭一些数据库链接和打开的临时文件 3.私有方法两个下划线开头,声明该方法为私 ...

  5. (转载)项目实战工具类(一):PhoneUtil(手机信息相关)

    项目实战工具类(一):PhoneUtil(手机信息相关)   可以使用的功能: 1.获取手机系统版本号 2.获取手机型号 3.获取手机宽度 4.获取手机高度 5.获取手机imei串号 ,GSM手机的 ...

  6. CF 287(div 2) B Amr and Pins

    解题思路:一开始自己想的是找出每一次旋转所得到的圆心轨迹,将想要旋转到的点代入该圆心轨迹的方程,如果相等,则跳出循环,如果不相等,则接着进行下一次旋转.后来看了题解,发现,它的旋转可以是任意角度的,所 ...

  7. category和关联对象

    如上所见,我们知道在category里面是无法为category添加实例变量的.但是我们很多时候需要在category中添加和对象关联的值,这个时候可以求助关联对象来实现. MyClass+Categ ...

  8. 《Unix环境高级编程》读书笔记 第3章-文件I/O

    1. 引言 Unix系统的大多数文件I/O只需用到5个函数:open.read.write.lseek以及close 本章描述的函数经常被称为不带缓冲的I/O.术语不带缓冲指的是在用户的进程中对其不会 ...

  9. 优动漫PAINT画树教程

    依次解析画树要点!让画树不再是难事~ 优动漫PAINT下载:http://wm.makeding.com/iclk/?zoneid=18597

  10. Mojo Core Embedder API

    This document is a subset of the Mojo documentation. Contents Overview Basic Initialization IPC Init ...