首页 > 解决方案 > 如何在 wordpress 中获取行数?

问题描述

我正在用 php 在 wordpress 上开发网站。我想从表中获取行数,我使用了这样的示例,但它不起作用。

我的代码:

$result = $wpdb->get_results("SELECT * FROM `wp_confirmation` WHERE user_id=$user_id");

if (count($result)> 0)
{
  //if its return count 0 need to be come here
}

标签: phpmysqlwordpress

解决方案


谢谢大家都回答我的问题,我现在得到了解决方案,我在下面给出了我的答案

$table_name = $wpdb->prefix . 'confirmation';
$my_query = $wpdb->get_results( "SELECT * FROM $table_name WHERE user_id=$user_id" );
$num_rows = count( $my_query ); //PHP count()
echo $num_rows;

推荐阅读