php - 如何在 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
}
解决方案
谢谢大家都回答我的问题,我现在得到了解决方案,我在下面给出了我的答案
$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;
推荐阅读
- serilog - Windows 8.1 (WinRT) 上的 Serilog.Sinks.File 支持
- apache-nifi - 集群Nifi运行不规律,经常出现问题
- css - 在智能手机中全屏打开 Leaflet Popup
- azure - 从 Azure 广告 B2C 帐户访问 Azure Blob 存储和 Key Vault
- excel - 在VBA中,如何从文本中提取数字前的字符串
- solr - SOLR 建议器中的上下文过滤
- php - Laravel Distinct 查询在我的项目中不起作用
- python - 无法制作计算树中非终端节点的程序
- javascript - 我尝试部署该功能时出错
- java - Spring JDBC获取地图列表