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

zblog1年前zblog问题解答47
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数组长度 count() 函数

在 PHP 中,你可以使用 count() 函数来获取数组的长度(或称为元素的数量)。count() 函数返回数组中元素的数量。下面是一个简单的示例: &nbs...

Storage engine MylSAM is disabled (Table creation is disallowed). mysql8++  MyISAM 或 InnoDB(8默认)数据库

Storage engine MylSAM is disabled (Table creation is disallowed). mysql8++ MyISAM 或 InnoDB(8默认)数据库

Storage engine MylSAM is disabled (Table creation is disallowed). mysql8++  MyISAM 或 InnoDB(8默认...

重启!

重启!

重启mysql 和 phpservice mysqld restart service php-fpm restart或systemctl restart mysqldsystemctl r...

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

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

linux升级 centos升级 centos软件升级 yum升级

linux升级 centos升级 centos软件升级 yum升级

sudo yum clean all sudo yum makecache sudo yum update 执行...