franckc2 Posted March 17, 2009 Share Posted March 17, 2009 Hi guys, I need help figuring out what is not working with my code. I use and mysql query to get manufacturers_id (see bellow code) //CODE $manufacturer_enum = tep_db_query("select manufacturers_id from products where products_id = '" . (int)$products[$o]['id'] . "'"); $manufacturer_enum_results = mysql_fetch_assoc($manufacturer_enum) //CODE When I do a printf of $manufacturer_enum_results and I get this (two results) //RESULTS Array ( [10] => 1 ) Array ( [11] => 1 ) //RESULTS To see if it's okay I used printf to count the array //CODE print_r(count($manufacturer_enum_results)); // But I get "11" as a result ... which from my point of view doesn't make any sense. I really would appreciate a hand on this. Thanks Franck Quote Link to comment https://forums.phpfreaks.com/topic/149801-how-top-count-number-of-item-in-an-array/ Share on other sites More sharing options...
sasa Posted March 17, 2009 Share Posted March 17, 2009 what is tep_db_query() function Quote Link to comment https://forums.phpfreaks.com/topic/149801-how-top-count-number-of-item-in-an-array/#findComment-786631 Share on other sites More sharing options...
The Little Guy Posted March 17, 2009 Share Posted March 17, 2009 Why mysql returns results, it returns the columns in an array, so I would assume that it is returning how many columns it found. If you would like to see how many rows it returned, use: mysql_num_rows Quote Link to comment https://forums.phpfreaks.com/topic/149801-how-top-count-number-of-item-in-an-array/#findComment-786648 Share on other sites More sharing options...
franckc2 Posted March 17, 2009 Author Share Posted March 17, 2009 what is tep_db_query() function function tep_db_query($query, $link = 'db_link') { global $$link; if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) { error_log('QUERY ' . $query . "\n", 3, STORE_PAGE_PARSE_TIME_LOG); } $result = mysql_query($query, $$link) or tep_db_error($query, mysql_errno(), mysql_error()); if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) { $result_error = mysql_error(); error_log('RESULT ' . $result . ' ' . $result_error . "\n", 3, STORE_PAGE_PARSE_TIME_LOG); } return $result; } Quote Link to comment https://forums.phpfreaks.com/topic/149801-how-top-count-number-of-item-in-an-array/#findComment-786758 Share on other sites More sharing options...
franckc2 Posted March 17, 2009 Author Share Posted March 17, 2009 Why mysql returns results, it returns the columns in an array, so I would assume that it is returning how many columns it found. If you would like to see how many rows it returned, use: mysql_num_rows mysql_num_rows give me the same "11" as result ...maybe I'm not using it right ... here is complet code portion $manufacturer_enum = tep_db_query_query("select manufacturers_id from products where products_id = '" . (int)$products[$o]['id'] . "'"); $manufacturer_enum_results = mysql_fetch_assoc($manufacturer_enum); $manufacturer_unique = array_unique($manufacturer_enum_results); print_r(count(mysql_num_rows($manufacturer_enum))); As you can see what I am trying to do is sort get every manufacturer form the product list. I need to see only unique Manufacturers so they are not duplicated in the list. After that I need to count how many different manufacturers they're is. Hope this can shed some light on what I am trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/149801-how-top-count-number-of-item-in-an-array/#findComment-786770 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.