zblog文章重复 判断文章是否存在

zblog1年前zblog问题解答64
1、方法1

$article = $zbp->GetListType('Post', 'select * from ' . $zbp->db->dbpre . 'post where log_ID = 111');    	 		 	  
if (empty($article[0])) {    	 		 	  
 //说明文章不存在
}

[dbpre] => zbp_ 是表前缀

2、方法2 

$article = $zbp->GetListType('Post', 'select * from ' . $zbp->table['Post'] . ' where log_ID = 111');    	 		 	  
if (empty($article[0])) {    	 		 	  
 //说明文章不存在
}

表名也可以也可以:$zbp->table['Post'] ## 支持   Post  Category Tag Comment Member Config Module Upload

3、方法3 
$where = array('=', 'log_ID', 111);
$num = $zbp->db->Query($zbp->db->sql->get()->select($zbp->table['Post'])->column('COUNT(a_id) num')->where($where)->sql)[0]['num'];
if ($num == 0) {
    // 说明文章不存在
}

直接sql 
$cate_id_rand = $zbp->db->Query("select cate_id as id from " . $zbp->table['Category'] . " order by rand() limit 1")[0]['id']; // 随机分类
#$mem_id_rand = $zbp->db->Query("select mem_id as id from " . $zbp->table['Member'] . " order by rand() limit 1")[0]['id']; // 随机用户


4、方法4 GetArticleList
$articles = $zbp->GetArticleList('*', array(array('=', 'log_Title', '我是标题')));

if (empty($articles)) { 
      // 如果没有相同标题的文章,则发布
}

5 方法5

$sql = $zbp->db->sql->get()->selectany('count(log_ID) num')->from($zbp->table['Post'])->where(array('=', 'log_Title', $title))->sql;
$num = $zbp->db->Query($sql)[0]['num'];
if ($num == 0) {
    // 说明文章不存在
}


相关文章

【zblog用户】获取用户作者的 select option选项

<?php echo OutputOptionItemsOfMember(0);?> 参数0是默认选中的作者id 输出 <optio...

ucs-4 这是啥编码 mb_convert_encoding($content, 'ucs-4', 'utf-8') 啥意思

UCS-4 是一种Unicode字符编码形式,全称为 Universal Character Set - 4 bytes。它是Unicode标准的一种实现,其中每个字符都使用4个字...

php 函数 array_unique 是干啥的 数组去重

`array_unique` 是 PHP 中的一个函数,用于从数组中移除重复的值。它返回一个新数组,其中包含原始数组中的唯一值,并保留原始键名。以下是 `array_unique` 函数的语法:```...

讯飞星火调试 https://xinghuo.xfyun.cn/desk?bug=s 讯飞调试

讯飞星火调试 https://xinghuo.xfyun.cn/desk?bug=s 讯飞调试...

Call to undefined function xnxf()zblog提示“可能的错误原因提示或500网络错误”时排查错误的方法

Call to undefined function xnxf()zblog提示“可能的错误原因提示或500网络错误”时排查错误的方法

很多时候都有可能遇到《错误提示》这类的提示,产生这个错误的原因一般来说都是服务端报错,如下图准备工作:1、进入后台,在网站设置的全局设置里,打开调试模式。2、如果不能进后台,那就用ftp连进网站,编辑...

zblog忘记密码怎么办?Z-BlogPHP密码找回工具 Z-BlogPHP

zblog忘记密码怎么办?Z-BlogPHP密码找回工具 Z-BlogPHP

zblog忘记密码怎么办?不要百度瞎折腾,直接按照官方解决方案干。https://bbs.zblogcn.com/thread-83419.html更新密码成功,退出再登录下,解决 修改后权限是访客,...