xbKappa Posted October 25, 2021 Share Posted October 25, 2021 I have this code for counting product attributes $getProductAttributes = Db::getInstance()->executeS('SELECT COUNT(id_product_attribute) FROM '._DB_PREFIX_.'product_attribute WHERE id_product = '.$id_product.''); print_r($getProductAttributes); and is printing this Array ( [0] => Array ( [COUNT(id_product_attribute)] => 90 ) ) how can i get only the value 90? Link to comment Share on other sites More sharing options...
Rhobur Posted October 26, 2021 Share Posted October 26, 2021 (edited) It should be like this, $getProductAttributes = Db::getInstance()->executeS('SELECT COUNT(id_product_attribute) FROM `'._DB_PREFIX_.'product_attribute` WHERE id_product='.(int)$id_product); print_r($getProductAttributes, true); then get the value from array. Edited October 26, 2021 by Rhobur clarity (see edit history) 1 1 Link to comment Share on other sites More sharing options...
coeos.pro Posted October 26, 2021 Share Posted October 26, 2021 Don't use executeS but getValue : $getProductAttributes = Db::getInstance()->getValue ('SELECT COUNT(id_product_attribute) FROM '._DB_PREFIX_.'product_attribute WHERE id_product = '.(int)$id_product); and then $getProductAttributes = 90 for security, don't forget (int) before $id_product 1 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now