NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Mysql counting query:

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 10-14-2006, 11:38 AM THREAD STARTER               #1 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
Join Date: Jan 2005
Location: UK
Posts: 2,408
PoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nice
 



Mysql counting query:


I currently have this mysql query:

Code:
SELECT c.*, s.* FROM categories c, subcategories s WHERE c.cat_id=s.cat_id GROUP BY c.cat_id ORDER BY c.cat_name ASC
Now I also want to count the amount of subcategories in a category (so that I can divide it by 3 for layout reasons! ). in the table "subcategories" I have "cat_id" which is linked to the categories table, "subcat_id" which isn't really of any use in this script, and "subcat_name". in the "categories" table I have "cat_name" and I have "cat_id".
????: NamePros.com http://www.namepros.com/programming/247220-mysql-counting-query.html

How would I go about doing it?

Thanks
Tom
PoorDoggie is offline  
Old 10-14-2006, 12:57 PM   #2 (permalink)
NamePros Member
Join Date: Sep 2006
Posts: 134
andysyme will become famous soon enoughandysyme will become famous soon enough
 



Not feeling very SQLey tonight, but is this anything close to what you want?

SELECT c.cat_name, COUNT(s.subcat_name)
FROM category c, subcategory s
WHERE c.cat_id = s.cat_id
GROUP BY c.cat_name

Andy
andysyme is offline  
Old 10-14-2006, 01:45 PM THREAD STARTER               #3 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
Join Date: Jan 2005
Location: UK
Posts: 2,408
PoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nice
 



no... but don't worry - i can do it another way.

Its my egotistic coding style where I want to cram as much as i can into the smallest amount of space! hehe... its ok, ill split it all up a bit! hehe... thanks
PoorDoggie is offline  
Old 10-14-2006, 01:59 PM   #4 (permalink)
NamePros Member
Join Date: Sep 2006
Posts: 134
andysyme will become famous soon enoughandysyme will become famous soon enough
 



Just tried this, it will give you a list of cats and the number of subcats in each.

Guess I didn't understand the question!!

Andy
andysyme is offline  
Old 10-14-2006, 02:10 PM THREAD STARTER               #5 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
Join Date: Jan 2005
Location: UK
Posts: 2,408
PoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nice
 



ok... i will try it then I am sure i had that before
PoorDoggie is offline  
Old 10-16-2006, 10:42 AM   #6 (permalink)
Senior Member
 
-Ray-'s Avatar
Join Date: Jun 2005
Location: Pennsylvania
Posts: 1,839
-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of
 



Originally Posted by PoorDoggie
no... but don't worry - i can do it another way.

Its my egotistic coding style where I want to cram as much as i can into the smallest amount of space! hehe... its ok, ill split it all up a bit! hehe... thanks
heh... thats how i code its the best way... less space, less bandwidth...
__________________
Poker News, articles, discussion
LIKE THIS

Its an iPod, a phone, and an internet communications device.
-Ray- is offline  
Old 10-16-2006, 01:19 PM THREAD STARTER               #7 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
Join Date: Jan 2005
Location: UK
Posts: 2,408
PoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nice
 



Originally Posted by templaterave
heh... thats how i code its the best way... less space, less bandwidth...
generally quicker scripts too! lol
PoorDoggie is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 04:37 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger