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

zblog1年前zblog问题解答38
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) {
    // 说明文章不存在
}


相关文章

PHP uniqid() 函数

uniqid() 函数基于以微秒计的当前时间,生成一个唯一的 ID。  <?php  echo uniqid();  &nb...

str_pad php 字符串左右补全填充到固定长度的函数

str_pad 是 PHP 中的一个字符串处理函数,用于将字符串填充到指定的长度。其基本语法如下:str_pad(string $input, int $pad_leng...

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

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

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

宝塔可以防采集吗?能,但是你大概率用不上!因为:正常用户也会弹出来验证!!!

宝塔可以防采集吗?能,但是你大概率用不上!因为:正常用户也会弹出来验证!!!

参见https://www.bt.cn/bbs/forum.php?mod=viewthread&tid=106744&highlight=%E9%98%B2%E9%87%87%E9%...

(phpsession)php session 增改删的例子 名字叫 baijiahao

当使用 PHP 会话(session)来存储、修改和删除名为 baijiahao 的数据时,你可以按照以下步骤进行操作:启动会话首先,你需要在每个需要使用会话的 PHP 脚本中启动会话。这通常是通过调...