close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

display number of occurrences of an item in a list

Thread began 4/09/2013 12:33 pm by Dennis | Last modified 4/12/2013 3:26 pm by Dennis | 1480 views | 11 replies |

Dennis

display number of occurrences of an item in a list

Hi,

I have a database that contains dogs name, year achieve AKC Champion, and kennel name.

I would like to enhance the search (or create a new search similar to) found here http://www.oldenglishsheepdogclubofamerica.org/champions_titled.php so when a year was imputed, the search results would display a column indicating the number of occurrences of a particular kennel name and sort by that column. So the end result would produce a list as can be seen in the first column found here (this is a static page created manually) http://www.oldenglishsheepdogclubofamerica.org/statistics/kennels_producing_champions.php.

The main part I am having trouble with is the calculating/displaying the number of occurrences of each kennel name.

Thanks,
Dennis

Sign in to reply to this post

Jason ByrnesWebAssist

you would need to use a nested recordset for this.

in the nested recordset you would use the count function to return the record count.

see the following tutorial for details on nested recordsets:
http://www.webassist.com/community/tutorials/view_tutorial.php?tid=12

the W3Schools page has details on using the MySQL Count function
http://www.w3schools.com/sql/sql_func_count.asp

Sign in to reply to this post

Dennis

Thanks Jason,

I think I have a good start with the nested recordset and Count function.

I'm having trouble with what to use for the WHERE clause in the nested (Count) recordset.

Also, how can I prevent the repeating of the same kennel names, and lastly how can I sort on the Count column.

Here is the link: http://www.oldenglishsheepdogclubofamerica.org/top_kennels_WA.php and attached is the file.

Thanks,
Dennis

Attached Files
top_kennels_WA.zip
Sign in to reply to this post

Jason ByrnesWebAssist

to prevent repetitions, and to order by the count, we'll need to do this a different way using only 1 recordset:


SELECT *, COUNT(idColumn) as recordCount FROM tableName GROUP BY kenelNameColumn ORDER BY COUNT(idColumn) ASC
Sign in to reply to this post

Dennis

Wonderful

Jason, that did the trick.

One thing that would be the icing on the cake, if it isn't to difficult, would be to have a second level sort on the kennel name. So the primary list sort would be by Count (which it is now) but within the same Counts the kennels would be sorted alphabetically.

Can that be done without to much difficulty?

Also could a TOTAL of all the counts be added.

Thanks,
Dennis

Sign in to reply to this post

Jason ByrnesWebAssist

SELECT *, COUNT(idColumn) as recordCount FROM tableName GROUP BY kenelNameColumn ORDER BY COUNT(idColumn), kenelNameColumn ASC




for the total count, you would need a second recordset:

SELECT COUNT(idColumn) as recordCount FROM tableName
Sign in to reply to this post

Dennis

So close...

Jason,

Sorting and everything but the total of counts is working great.

But for the Total count I get the total of the columns in the database, not the totals from the query listed on the page.

I even tried substituting the alias in the first recordset for the COUNT (columned) in the 2nd recordset, but I get a MySQL error for that.

http://www.oldenglishsheepdogclubofamerica.org/top_kennels_WA.php

Dennis

Attached Files
top_kennels_WA.zip
Sign in to reply to this post

Jason ByrnesWebAssist

I guess i dont follow what you want to accomplish, I thought you wanted to show the total records from the database?

Sign in to reply to this post

Dennis

Jason,

I want to display the total of all the counts (champions) displayed on the page by the recordset you helped me with. So if the search displays...
Kennel A 5 champions
Kennel B 4 champions
Total 9

To show the TOTAL you suggest the code (recordset) SELECT COUNT(idColumn) as recordCount FROM tableName
which makes sense, but I don't have an idColumn instead the recordset you suggested (reply #4 above) to create the list of champions uses an alias (I believe). Using that alias in place of idColumn gives an MySQL error.

The page can be seen here (I don't know how to make it a link with the new forum) - http://www.oldenglishsheepdogclubofamerica.org/top_kennels_WA.php

Dennis

Sign in to reply to this post

Jason ByrnesWebAssist

I see now, change the recordset code:

php:
$query_rsTotalCount = "SELECT COUNT(champions_id) as totalCount FROM champions";

$rsTotalCount = mysql_query($query_rsTotalCount, $connOESCA) or die(mysql_error());




to:

php:
$query_rsTotalCount = "SELECT COUNT(champions_id) as totalCount FROM champions";

setQueryBuilderSource($query_rsTotalCount,$WADbSearch1,false);
$rsTotalCount = mysql_query($query_rsTotalCount, $connOESCA) or die(mysql_error());
Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...