简体   繁体   中英

wordpress - trying to use count() inside $wpdb->get_results but returns empty result

I am trying to get how many rows contains the same product id in this table. I mean how many times a product is repeated in this table for example product id = 1000 and number of instances is 3. This is my code:

$prod_id_query = "SELECT prod_id , COUNT(prod_id)    AS repeat_num  FROM {$wpdb->wlfmc_items} GROUP BY prod_id  ";
$prods_ids = $wpdb->get_results($prod_id_query);      
print_r($prods_ids);  

but the result is empty. It returns empty array.

thanks for everyone tried to help i found that the problem was with (AS repeat_num FROM) the corrrection is the semicolon >> ( AS 'repeat_num' FROM )

iam using mariaDB

now it's working thanks

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