You are here:  » Count Alphabetically?

Support Forum



Count Alphabetically?

Submitted by ph on Fri, 2010-01-22 13:27 in

Hi There

I have used snippet of code you created to count the amount of brands and products in store etc. but is it possible to cound the amount of brands beginning with 'A', 'B', 'C' etc?

i.e. I want to display a couple of brands beginning with 'G' for example, then have a link that says "View all xx brands" where "xx" is the total amount of brands beginning with 'G'.

thanks

PH

Submitted by support on Fri, 2010-01-22 14:25

Hi,

Sure - the $sql to select and show the count for "G" for example would be:

$sql = "SELECT COUNT(DISTINCT(brand)) AS brandCount FROM `".$config_databaseTablePrefix."products` WHERE brand LIKE 'G%'";
database_querySelect($sql,$rows);
print $rows[0]["brandCount"]." brands beginning with G";

If you're not sure how to merge that with your existing code (presumably taking "G" in this case from a variable) let me know - if you could post the code you are using that would help and I'll show where to insert / modify the above...

Cheers,
David.

Submitted by ph on Fri, 2010-01-22 14:59

Hi David

that's great. I had to change it slightly and add a couple of semi-colons to merge it with my code, but it's working perfect now.

$sql = "SELECT COUNT(DISTINCT(brand)) AS brandCount FROM `".$config_databaseTablePrefix."products` WHERE brand LIKE 'G%'";
database_querySelect($sql,$rows);
print $rows[0]["brandCount"]." brands beginning with G";

Cheers

PH

Submitted by support on Fri, 2010-01-22 15:04

Ooops! Thanks for letting me know - i've corrected the code above...

Cheers,
David.