Jump to content

Counting Entry Values (Excluding Duplicates)


sintax63

Recommended Posts

I want to display something like this on my site:

There are currently 63 lodges in 12 states listed

 

The "63  lodges" part is easy as I am just counting the rows. The number of states is giving me issues however. I have a column in my table called "states" which obviously contains duplicate entries. For example, I have IL in the table 8 times but only want it to count "IL" as 1 to add to the total value.

 

Is something like that possible?

 

Thanks in advance!

 

  Quote

Let's see the query... DISTINCT is not an expression.

 

If you are talking to me, Fenway - this is all I have...

$lodges	= mysql_result(mysql_query("SELECT COUNT(*) FROM lodges WHERE status='1'"),0);

 

Which I am using to just count the rows. I don't have anything for the states yet because I'm not sure how to go about doing it.  :-[

$states	= mysql_result(mysql_query("SELECT COUNT(*), COUNT( DISTINCT states ) FROM lodges WHERE status='1'"),0);

 

Produced:

 

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/public_html/index.php on line 8

 

  Quote

Nope!  ;)

 

That doesn't do the trick either...

How does it "not do the trick"? The query executes correctly, right?  You need to use fetch the appropriate columns, though -- you should add column aliases and use mysql_fetch_assoc().

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.