简体   繁体   English

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

[英]How would I count the number of rows returned from an sql query using wordpress?

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'. 这使我得到“ 61”,即整个数组中元素的总数,该数组是std对象的数组,每个对象都是对应于我指定的查询的一行,即Donor列等于'戴夫”。

There are 6 instances where this is true, how would I return this number (6) and not 61? 在6种情况下,这是正确的,我将如何返回此数字(6)而不是61?

This is driving me nuts. 这让我发疯。

如果在Select中使用count会发生什么?

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

try this here is salutation i hope helped out 尝试这里,这是称呼,希望对您有所帮助

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

echo $wpdb->num_rows;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM