How do I count specific, smaller groups of information in one large table?


hello all,

 

i have feeling answer right under nose, somehow, evading me.

 

i able count how many photos in specific gallery. why? well, on toc page, thought cool show  user how many photos in given gallery displayed on screen part of gallery data i'm presenting. it's not necessary, believe adds nice touch. my  thought have 1 massive table containing photo information , massive table containing gallery  information, , do. can pull various gallery information  based on user selections, accurately counting correct number of  images per gallery evading me.

 

in db, have table, 'galleries', has several columns, 2 relevant g_id , g_spe. g_id primary key , ai column represents gallery 'serial' number. g_spec value have 1 of 11 different values in (not relevant topic.)

 

additionally, there table, 'photos', , in table 3 columns:  p_id, g_id , p_fname. p_id primary key, g_id foreign key (primary key of 'galleries' table) , p_fname contains filename of each photo in ever-expanding gallery.

 

here's abbreviated contents of galleries table showing first 2 columns:

 

(`g_id`, `g_spec`, etc...)
(1, 11, etc...),
(2, 11, etc...),
(3, 11, etc...),
(4, 11, etc...),
(5, 12, etc...),
(6, 13, etc...)

 

here's contents of photos table far, populated test images:

 

(`p_id`, `g_id`, `p_fname`)

(1, 1, '1_dsc1155.jpg'),
(2, 1, '1_dsc1199.jpg'),
(3, 1, '1_dsc1243.jpg'),
(4, 1, '1_dsc1332.jpg'),
(5, 1, '1_dsc1381.jpg'),
(6, 1, '1_dsc1421.jpg'),
(7, 1, '1_dsc2097.jpg'),
(8, 1, '1_dsc2158a.jpg'),
(9, 1, '1_dsc2204a.jpg'),
(10, 1, '1_dsc2416.jpg'),
(11, 1, '1_dsc2639.jpg'),
(12, 1, '1_dsc3768.jpg'),
(13, 1, '1_dsc3809.jpg'),
(14, 1, '1_dsc4226.jpg'),
(15, 1, '1_dsc4257.jpg'),
(16, 1, '1_dsc4525.jpg'),
(17, 1, '1_dsc4549.jpg'),
(18, 2, '2_dsc1155.jpg'),
(19, 2, '2_dsc1199.jpg'),
(20, 2, '2_dsc1243.jpg'),
(21, 2, '2_dsc1332.jpg'),
(22, 2, '2_dsc1381.jpg'),
(23, 2, '2_dsc1421.jpg'),
(24, 2, '2_dsc2097.jpg'),
(25, 2, '2_dsc2158a.jpg'),
(26, 2, '2_dsc2204a.jpg'),
(27, 2, '2_dsc2416.jpg'),
(28, 2, '2_dsc2639.jpg'),
(29, 2, '2_dsc3768.jpg'),
(30, 2, '2_dsc3809.jpg'),
(31, 2, '2_dsc4226.jpg'),
(32, 2, '2_dsc4257.jpg'),
(33, 2, '2_dsc4525.jpg'),
(34, 2, '2_dsc4549.jpg'),
(35, 3, '3_dsc1155.jpg'),
(36, 3, '3_dsc1199.jpg'),
(37, 3, '3_dsc1243.jpg'),
(38, 3, '3_dsc1332.jpg'),
(39, 3, '3_dsc1381.jpg'),
(40, 3, '3_dsc1421.jpg'),
(41, 3, '3_dsc2097.jpg'),
(42, 3, '3_dsc2158a.jpg'),
(43, 3, '3_dsc2204a.jpg'),
(44, 3, '3_dsc2416.jpg'),
(45, 3, '3_dsc2639.jpg'),
(46, 3, '3_dsc3768.jpg'),
(47, 3, '3_dsc3809.jpg'),
(48, 3, '3_dsc4226.jpg'),
(49, 3, '3_dsc4257.jpg'),
(50, 3, '3_dsc4525.jpg'),
(51, 3, '3_dsc4549.jpg');

 

for now, each gallery has 17 images random number chose.

 

i need able write query says, tell me how many photos in specific photoset (in photos table) based on number in galleries.g_id  , photos.g_id being equal.

 

as see in photos table, p_id column ai column (call photo serial numbers), , g_id column assigns each specific photo specific gallery number equal gallery id in galleries.g_id table. specifically, example want have query count number of rows in photos table g_id = 2 when referenced g_id = 2 in galleries table.

 

i have been messing different distinct , count methods, seem limited working 1 table, , here, need reference 2 tables acheive result.

 

would better if each gallery had own table?

 

it should bloody simple, it's not clear.

 

please let me know if have left out key information, , thank in advance kind , generous help.

 

sincerely,

 

wordman

if understand correctly, don't need reference gallery table this:

 

select g_id, count(*) photos

group g_id



More discussions in Develop server-side applications in Dreamweaver


adobe

Comments

Popular posts from this blog

Joomla site hacked, cant see front and - Joomla! Forum - community, help and support

Christian Home School Programs - Joomla! Forum - community, help and support

Trouble with PF_OutFlag_I_USE_AUDIO and PF_CHECKOUT_LAYER_AUDIO