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!

 

Link to comment
Share on other sites

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.  :-[

Link to comment
Share on other sites

$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

 

Link to comment
Share on other sites

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().

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.