如何检查WordPress的自定义表是否为空 [英] how to check wordpress custom table is empty or not

查看:85
本文介绍了如何检查WordPress的自定义表是否为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关wordpress表格的问题. 我正在创建一个插件,我想检查名为wp_school_post的表是否为空.

This question about wordpress cutom table.. I am creating a plugin I want to check a table named wp_school_post table empty or not.

请参阅下面的代码,该错误将引发以下错误

See my code below which throws the following error

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\getwp\wp-content\plugins\getwp_P\schools_post_function.php on line 7

**filled** 

我的代码:

function schools_post_function()
{
//  echo "Sachool POST function";
    global $wpdb;
    $result = $wpdb->get_results("SELECT postid from wp_school_post WHERE `postid` IS NOT NULL");
    if(mysql_num_rows($result=='0'))
    {
        echo "not filled";
    }
    else
    {
        echo "filled";

    }
}

推荐答案

尝试一下:)

<?php
function schools_post_function()
{
    global $wpdb;
    $result = $wpdb->get_results("SELECT postid from wp_school_post WHERE `postid` IS NOT NULL");
    if(count($result) == 0)
    {
        echo "not filled";
    }
    else
    {
        echo "filled";

    }
}
?>

这篇关于如何检查WordPress的自定义表是否为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆