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. 【SPOJ-GSHOP】Rama and Friends【贪心】【细节】

    题意: 给出n个非严格递增的整数(可能有负数),必须操作k次.每次能够把当中一个数变为它的相反数,使得终于的数列和最大. 输出这个最大和. 考验怎样出坑数据卡自己的程序... #include < ...

  2. 【LeetCode-面试算法经典-Java实现】【145-Binary Tree Postorder Traversal(二叉树非递归后序遍历)】

    [145-Binary Tree Postorder Traversal(二叉树非递归后序遍历)] [LeetCode-面试算法经典-Java实现][全部题目文件夹索引] 原题 Given a bin ...

  3. Hadoop解析--MapReduce

    从本篇博客開始咱们一起来具体了解Hadoop的每一个部分.我们在上篇博客中介绍了HDFS,MapReduce,MapReduce为了更有效率事实上是建立在HDFS之上的.有了分布式的文件系统,我们就能 ...

  4. MySQL超级简明基本操作攻略,给自己看(一)

    系统:Ubuntu 14.04 LTS 安装: apt-get install mysql //安装数据库 apt-get install mysql-workbench //安装图形界面 使用: 启 ...

  5. Checkmarx VisualStudio plugin installation process.

    1-      Configuration of plugin VSTudio Prerequisite: -Your visual studio MUST be up to date with th ...

  6. phpstorm 或 webstorm 设置打开多个项目,多个项目并存。

    File -> settings -> Directories -> Add Content Root 中添加你当前的工程目录. 这样就可以节省内存了.之前用一个打开php项目,一个 ...

  7. nyoj--514--1的个数(贪心)

     1的个数 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 给你两个数a和b,你的任务是计算出1在a和b之间出现的次数,比如说,如果a=1024,b=1032,那么a ...

  8. spark集群体系结构

  9. java中return在Try-Catch中的执行顺序

    我们知道return会结束此方法并返回指定值.以及在Try-catch-finally中无论try代码块中有没有异常finally中的代码时都会被执行的.但是如果return包含在try-catch- ...

  10. 新疆大学OJ(ACM) 1047: string 字符串排序

    1047: string 时间限制: 1 Sec  内存限制: 128 MB 题目描述 有n个字符串字符串n<=50000,把所有字符串串起来,得到一个字典序最小的字符串. 输入 输入第一行是一 ...