[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 10-14-2006, 10:38 AM   #1 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
 
Join Date: Jan 2005
Location: UK
Posts: 2,390
316.50 NP$ (Donate)

PoorDoggie 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".

How would I go about doing it?

Thanks
Tom
PoorDoggie is offline  
Old 10-14-2006, 11:57 AM   #2 (permalink)
NamePros Member
 
Join Date: Sep 2006
Posts: 132
0.00 NP$ (Donate)

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
__________________
Coming soon - POCHost.com
andysyme is offline  
Old 10-14-2006, 12:45 PM   #3 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
 
Join Date: Jan 2005
Location: UK
Posts: 2,390
316.50 NP$ (Donate)

PoorDoggie 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, 12:59 PM   #4 (permalink)
NamePros Member
 
Join Date: Sep 2006
Posts: 132
0.00 NP$ (Donate)

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
__________________
Coming soon - POCHost.com
andysyme is offline  
Old 10-14-2006, 01:10 PM   #5 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
 
Join Date: Jan 2005
Location: UK
Posts: 2,390
316.50 NP$ (Donate)

PoorDoggie 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, 09:42 AM   #6 (permalink)
An American Soldier
 
-Ray-'s Avatar
 
Join Date: Jun 2005
Location: Pennsylvania
Posts: 1,630
2.53 NP$ (Donate)

-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold


Quote:
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...
__________________
Completely Free cPanel Hosting
-- Deployed to Afghanistan --
"There is no such thing as rich over-night unless you owned Google stock in 2006"
-Ray- is offline  
Old 10-16-2006, 12:19 PM   #7 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
 
Join Date: Jan 2005
Location: UK
Posts: 2,390
316.50 NP$ (Donate)

PoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nice


Quote:
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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 02:36 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85