简体   繁体   中英

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'.

There are 6 instances where this is true, how would I return this number (6) and not 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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