我如何计算使用wordpress从sql查询返回的行数?

我如何计算使用wordpress从sql查询返回的行数?

问题描述:

I am currently using:

$dup_donor_count = count($wpdb->get_results("SELECT * FROM ".$table_name." WHERE Donor = '".$donor."'"));

which is giving me back '61', the total number of elements in the entire array, the array is an array of std objects, each of which is a row corresponding to my specified query, namely, where the Donor column is equal to 'Dave'.

There are 6 instances where this is true, how would I return this number (6) and not 61?

This is driving me nuts.

我目前正在使用: p>

  $ dup_donor_count = count(  $ wpdb-> get_results(“SELECT * FROM”。$ table_name。“WHERE Donor ='”。$ donor。“'”)); 
  code>  pre> 
 
 

给我回'61',整个数组中的元素总数,该数组是一个std对象数组,每个对象都是一个对应于我指定查询的行,即Donor列等于'Dave '。 p>

有6个实例,这是真的,我如何返回这个数字(6)而不是61? p>

这是在推动我 坚果。 p> div>

try this here is salutation i hope helped out

$wpdb->get_results("SELECT FROM ".$table_name." WHERE Donor = '".$donor."'");

echo $wpdb->num_rows;

What happens if you are using count inside the Select?

$dup_donor_count = $wpdb->get_results("SELECT COUNT(*) FROM ".$table_name." WHERE Donor = '".$donor."'");