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

Hello all,
I have a feeling the answer to this is right under my nose, but somehow, it is evading me.
I would like to be able to count how many photos are in any specific gallery. Why? Well, on my TOC page, I thought it would be cool to show  the user how many photos were in any given gallery displayed on the screen as part of all the gallery data I'm presenting. It's not necessary, but I believe it adds a nice touch. My  thought was to have one massive table containing all the photo information and another massive table containing the gallery  information, and currently I do. I can pull various gallery information  based on user selections, but accurately counting the correct number of  images per gallery is evading me.
In my DB, I have the table, 'galleries', which has several columns, but the two most relevant are g_id and g_spe. g_id is the primary key and is an AI column that represents also the gallery 'serial' number. g_spec is a value that will have one of 11 different values in it (not relevant for this topic.)
Additionally, there is the table, 'photos', and in this table are three columns:  p_id, g_id and p_fname. p_id is the primary key, g_id is the foreign key (primary key of the 'galleries' table) and p_fname contains the filename of each photo in my ever-expanding gallery.
Here's the abbreviated contents of the galleries table showing only the 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 the contents of my photos table so far, populated with 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 which was just some random number I chose.
I need to be able to write a query that says, tell me how many photos are in a specific photoset (in the photos table) based on the number in galleries.g_id  and photos.g_id being equal.
As you see in the photos table, the p_id column is an AI column (call it photo serial numbers), and the g_id column assigns each specific photo to a specific gallery number that is equal to some gallery ID in the galleries.g_id table. SPECIFICALLY, for example I would want to have the query count the number of rows in the photos table whose g_id = 2 when referenced to g_id = 2 in the galleries table.
I have been messing with different DISTINCT and COUNT methods, but all seem to be limited to working with just one table, and here, I need to reference two tables to acheive my result.
Would this be better if each gallery had its own table?
It should be so bloody simple, but it's just not clear.
Please let me know if I have left out any key information, and thank you all in advance for your kind and generous help.
Sincerely,
wordman

bregent,
I got it!
Here's the deal: the query that picks the subset of records:
$conn = dbConnect('query');
$sql = "SELECT *
        FROM galleries
        WHERE g_spec = '$spec%'
        ORDER BY g_id DESC
        LIMIT $startRow,".SHOWMAX;
$result = $conn->query($sql) or die(mysqli_error());
$galSpec = $result->fetch_assoc();
picks 3 at a time, and with each record is an individual gallery number (g_id). So, I went down into my code where a do...while loop runs through the data, displaying the info for each subset of records and I added another query:
$conn = dbConnect('query');
$getTotal = "SELECT COUNT(*)
            FROM photos
            WHERE g_id = {$galSpec['g_id']}
            GROUP BY g_id";
$total = $conn->query($getTotal);
$row = $total->fetch_row();
$totalPix = $row[0];
which uses the value in $galSpec['g_id']. I didn't know the proper syntax for including it, but when I tried the curly braces, it worked. I altered the number of photos in each gallery in the photos table so that each total is different, and the results display perfectly.
And as you can see, I used some of the code you suggested in the second query and all is well.
Again, thank you so much for being patient and lending me your advice and assistance!
Sincerely,
wordman

Similar Messages

  • How do you count the multiple columns of a field in a table

    How do you count the multiple columns of a field in a table

    Hi,
    4396bf34-e890-4202-a6b0-4e08c9ff0e89 wrote:
    How do you count the multiple columns of a field in a table
    Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002
    "Field" isn't a standard database term.  Some people say "field" when they mean "column", but I don't think that's what you mean ("How do you count the multiple columns of a column ..").  Do you want to know how many times a column is used (as opposed to NULL), or the number of different values in a column?  You really need to show what you want.

  • Cisco ACS 5.3 - How to only allow specific AD groups to login

    Can anyone help me figure out what I have wrong or have missing?
    I've configured three specific AD groups, Admin, Storage, and HelpDesk, with their own commands sets.
    This seems to be working fine, but everyone can log into everything, but they can't do anything except exit.
    My goal is to not allow anyone to login that is not part of the three AD groups I have specified with the respective command sets.
    All the logins hit the Admin account, even though the id in AD is not in the that AD group.  I have something screwed up.

    Check your authorization rules, make sure the default rule isnt set to Permit. Group Mapping is only mapping AD groups to internal ACS groups, we need to check your authorization rules to see which policies they users are hitting, you may want to reset the hit count and test to see which policy is allowing access.
    Thanks,
    Tarik Admani
    *Please rate helpful posts*

  • Mashing small clips together to make one large one!?

    i figured ou thow to do this once, but now i cant remember.
    i need to mesh a bunch of small clips together to make a large one so i can do a longer transition.

    .. if You had some short clips and applyed a text on them.
    And the text just using some spaces (no letters) then it would merge the
    clips together...
    never tried (.. never needed.. ), but a clever one!!
    here's for you:

  • How can I import several small audio files to create one BIG file in iTunes

    I have ONE cd with THREE audio stories contained in EIGHTEEN audio files (6 files make each story). I also have an iMac. Not sure if they're mp3 or not, but they play on computers and car radios.
    How can I take this CD, whisper abracadabra and end up with three files (each with one story)? Don't need to re-burn a CD, but just need to get them on to an iPod.
    I've tried inserting the CD and using the right mouse click/info/options to select 6 files and identify them as a 'gapless album' - but this did not link the files together.
    Any help you can offer would be appreciated. I have read pages & pages of topics, but could not find this particular issue.

    Insert the CD.
    Don't Import it yet.
    Select the CD in iTunes.
    Select the consecutive tracks uyou want joined as one file.
    Go to menu Advanced > Join CD tracks.
    Do this for each set of tracks you want as one file.
    Then Import the CD.
    If the tracks are already in iTunes, no need to import them again.
    Use this -> Join Together
    "Join Together automates the process of joining the files of selected iTunes tracks together with QuickTime and exporting them as a single AAC Music or Audiobook file/track. Optionally, you can then create a "chapterized" audio file of the exported AAC file with pointers to the individually joined tracks."

  • How do I put a scattered group of events into one calendar?

    I have perhaps 60 events scattered over the past 10 months that I would like to put into a single colored calendar.
    They are presently in the Home calendar.
    Is there a way to do this en bloc without having to assign each event seperately?
    I-Mac Mountain Lion 10.8.3

    No, Pages doens't have "shrink to fit". What I do is first cut down the margins to enlarge the text area a bit. If that doesn't do it, I Command-A to select all the text and start decreasing the text size a point at a time. When the last line pops onto the first page, you're done.
    Jerry.

  • How to mention User specific fileshare as Hard coded value in DB table

    I have a scenario like whenever the user clicks on Print, the application will generate a temp file Temp.txt and place it in fileshare location that is given in Database hard coded value as C:\Test, The problem here is when more than one user clicks on print button, the second user is getting error, as the same file is being used by first user.
    To save the temp file, I want to mention a locaton something like "C:\Documents and Settings\<User Id>" where <user Id> will be '0001' for user one and '0002' for user two. (0001 and 0002 are suppose to be the user login name within the organisation). Is there anyway to specify the user id of the active user as a hard coded value?

    take the output of select user from dual; in a variable and then append that either with file name or with directory location..

  • Can I use InDesign to format several small multiple-page PDFs into one large multiple-page PDF?  I want to stack 6 identical 3"x4" PDFs (50 pages long) onto one 8.5"x11" PDF (50 pages long) without having to align each image on each page individually.

    This seems like a standard thing that professional printers would have to do to efficiently maximize paper usage.  Can it be done with InDesign?

    Okay, thanks!  However, just to make sure, can I place a multi-page PDF (or InDesign document) onto a larger InDesign document that will automatically align each page in the same place all the way down the InDesign document? I am not looking to place single PDF pages one at a time because that will be highly inefficient for my purposes (I am going to have over 400 different 50-page 3"x4" PDFs that I wish to stack up 6 times on to a 50-page 8.5"x11" InDesign document).  How do I acquire/use the scripts that automate placing multi-page PDFs? Thanks!

  • How can I have multiple fields on the left and one large field on the right?

    I'm trying to conserve space on a form.  I have five "pass/fail" fields on the left and would like a large free text field to the right.  This will be an area to comment on the "pass/fail" section.  When I add the multi-line text box, it moves all my "pass/fail" mulitple selection boxes.
    Any advice?

    Sorry FormsCentral doesn't allow a fields to spam over multiple rows.
    Gen

  • How to extract data into excel file from more than one internal table

    Hi Guys
                 I want to extract the data from module pool screen.
                 In screen there are two internal tables
                      1. header
                      2. items.
                 I want to extract the data as same format looking in the screen.
                 With simple Download FM we cannot do this one, because in this we   will display as continuous rows.
    <b> But my requirement is saving as table with heading, date, header details</b>
    Note that it is not the simple down load . Suggest me with example  coding

    Hi Guys,
      I think it depends on which software you will use to see the result.
      If U are using Excel, it's very easy to achieve it.
      1. Define a structure as string, the lenth depend on your need.And use the structure to define a internal table, supposed is as A..
      2. Concatenate the head data using some separator, for ex. a comma; and then add this into A.
      3. The above step's concatenate is depend on your format for request;For ex, you want to place the date at the 4th cell in excel, that means you should put three separator before the date field.
      4 Concatenate the item data into the download table.
      5. Download the table to file.
      6. Display the file, using your defined separator.
    Hope this helpful.
    Bob

  • OS X Maverick Multi Display Support for grouping multiple monitors into one display?

    Will the new Mac Pro be capable of grouping multiple monitors into one large display?  Similar to AMD Eyefinity for the purpose of gaming.

    The current Mac Pro, or any Mac released since 1987 that can support multiple displays can ALREADY support combining all attached displays into one Extended Desktop, onto which you can open the gaming window and game across multiple displays. It is built into the System Software.

  • How to pass one's tables information to another

    Hello :
    i would like to one favor iam trying to send some specific information from one internal table to another,
    but when i make the APPEND the information doesn't apear in the destiny table(r_omisiones_nocreadas) , this a segment of the code that iam using:
    LOOP AT t_patrones.
    READ TABLE t_seleccion WITH KEY entidad = t_patrones-entidad BINARY SEARCH.
    Si la entidad para PSCD y SICOP,coincide con la entidad de SIE (la
    cual puede ser diferente debido a que tiene una dirección de
    notificacion independiente), se suman los importes.
        IF t_patrones-entidad = t_patrones-entidad_sie.
          w_aportacion = t_patrones-aportacion + t_patrones-aportacion_sie.
          w_amortizacion = t_patrones-amortizacion +
                           t_patrones-amortizacion_sie.
          w_subtotal = w_aportacion + w_amortizacion.
          IF NOT ( ( w_amortizacion >= t_seleccion-amortizacion ) OR
                   ( w_subtotal >= t_seleccion-aportacion ) ).
         No se alcanza el importe requerido para efectuar la notificación
    IF t_omisiones-patron = t_patrones-patron.
      APPEND r_omisiones_nocreadas
      MOVE 'No cumple con el rango de importes' TO r_omisiones_nocreadas-nocreado.
    ENDIF.
    this segement of code try to eliminate some information and when this informations is eliminated should be pass to the destiny table r_omisiones_nocreadas.
    i would appreciate if you have any answer for me thanks a lot

    Hi,
    LOOP AT t_patrones.
    READ TABLE t_seleccion WITH KEY entidad = t_patrones-entidad BINARY SEARCH.
    Si la entidad para PSCD y SICOP,coincide con la entidad de SIE (la
    cual puede ser diferente debido a que tiene una dirección de
    notificacion independiente), se suman los importes.
    IF t_patrones-entidad = t_patrones-entidad_sie.
    w_aportacion = t_patrones-aportacion + t_patrones-aportacion_sie.
    w_amortizacion = t_patrones-amortizacion +
    t_patrones-amortizacion_sie.
    w_subtotal = w_aportacion + w_amortizacion.
    IF NOT ( ( w_amortizacion >= t_seleccion-amortizacion ) OR
    ( w_subtotal >= t_seleccion-aportacion ) ).
    No se alcanza el importe requerido para efectuar la notificación
    IF t_omisiones-patron = t_patrones-patron.
    r_omisiones_nocreadas = t_patrones.APPEND r_omisiones_nocreadas.MOVE 'No cumple con el rango de importes' TO r_omisiones_nocreadas-nocreado.
    ENDIF.
    Thanks,
    Pramod

  • Hello. I began with the DPS. Is it possible to publish a magazine for a limited, specific target group? For example, in one department of a large company? Or to the responsible for various services? If so, how should I do? Thank you for your help.

    Hello.
    I began with the DPS. Is it possible to publish a magazine for a limited, specific target group? For example, in one department of a large company?
    Or to the responsible for various services? If so, how should I do? Thank you for your help.

    Short answer is yes.
    Click the request for consultation link in Digital Publishing Suite Help | DPS pricing options to receive a price estimate for the DPS license your project.

  • How do I count objects of a specific type in a Vector? Java 1.3 source.

    How do I count the objects of a specific type in a Vector?

    isInstance may allow too much for your needs as it allows any object which can be typecast to 'type' while you seem to want to limit to objects which are exactly of the type 'type'. In such a case you could do this:
    for (Enumeration e = attachmentTypes.elements(); e.hasMoreElements();)
      Object check = e.nextElement();
      if (check.getClass().equals(type)) {
        counter++;
    }Javadoc of the isInstance() method:
    http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Class.html#isInstance%28java.lang.Object%29
    (I link to the old Javadoc given you mentioned Java 1.3 compatible source)

  • How do I read & update email group subscription status for a specific contact via api?

    Looking at Eloqua's api documentation, I can find out how to update contacts, and even the global subscription flag, however we want to build a page on our custom website whcih allows users to opt in and out of specific email groups (as can be done manually from the contact page / preferences tab)
    I cant find the appropriate api documentation for this - I found a page for contacts:
    REST API - Contact Fields
    and a page for email group:
    REST API - Email Groups
    any idea how can I find and udpate the object linking the two ?!?

    Via REST API, the bare bones call is:
    PUT /API/REST/2.0/data/contact/{contactid}/email/group/{groupid}/subscription
      "type": "ContactEmailSubscription",
      "contactId": "3174",
      "emailGroup": {
      "type": "EmailGroup",
      "id": "15",
      "depth": "minimal",
      "name": "Test Email Group"
      "isSubscribed": "false"
    Where isSubscribed can be toggled to true. This is the same call made by the UI when you open the contact record, move to the preferences tab and right click to subscribe or unsubscribe on an email group:
    The list of email groups and their ids can be obtained via GET /assets/email/groups. I recommend adding ?depth=minimal to avoid retrieving unnecessary configuration information.
    Best regards,
    Bojan

Maybe you are looking for