This topic is locked

Sort by number of Master/Detail records

1/5/2009 9:54:19 AM
PHPRunner General questions
K
Khris author

I've designed a basic Service Call database which has an "Open" table setup in a Master/Detail relationship with the parent table of "Service". Next to the Open link is the number of open service calls currently entered. I have a number of different entries on the main "Service" table, each with a number of child records underneath it. Is there a way to sort this list by the number of open child links?

T
thesofa 1/5/2009

in the sql query for the "Service table", add a line to count the child records where link from service to child and child is not completed.

include this in the list view for the service table and then sort by clicking on the column header!
So first, create a link from `Service` to `Open` in the master detail page

then add line

count `open`.`id` as Open_Calls;

include `Open_Calls` in the list page

HTH

J
Jane 1/5/2009

Hi,
you can do the following:

  1. join master and detail table on the Edit SQL query tab,
  2. count number of details records in this query and use this value in the ORDER BY clause.

    Here is a sample:
    select `Service`.`field1`,

    `Service`.`field2`,

    count(`Open`.`IDField`) as details_sum

    from Service inner join Open

    on ...

    Group By ...

    Order By count(`Open`.`IDField`)

K
Khris author 1/5/2009

The only problem with your suggestion Jane is that it now only displays the lines that have open jobs. If there are no open jobs, the "Company" is no longer listed.

J
Jane 1/6/2009

Hi,
use RIGHT JOIN or LEFT JOIN instead of INNER JOIN in your SQL query.

K
Khris author 1/6/2009

Tried that yesterday already but it doesn't seem to make a difference.

J
Jane 1/7/2009

Hi,
It's difficult to tell you what's happening without seeing actual files.
Please publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions on reproducing this error.

K
Khris author 1/7/2009

Ticket has been submitted.