This topic is locked

how to get the value of the number of child records

3/4/2025 5:12:42 PM
PHPRunner General questions
P
psiconsultants author

I have a [Master] <==> [Details] table link set up. I know that I can select the checkbox "Display a number of child records" and I can see the child record counts perfectly fine, but because I will have lots of detail tables (more than 20) the users want to see a background color (i.e. red) shaded for the specific master fields where there are 0 child records, otherwise keep the normal background color.

I can see on the Designer page for the list page properties, the values of the item id. By default, the object was named "details_preview" but I changed it to "details_company". The help link shows me how to show or hide the element, but I don't see how I can get the specific value of the element.

What I would like to do is something like this:

if ((value of details_company count) == 0)
$record["company_name_css"].='background:red';

I just can't figure out how to capture the actual count value for item id = "details_company".

I'm mostly there and I have figured out how to change the background color of the specific field. In my testing, I simply checked for missing values, for example,

if ($data["company_name"] == "")

$record["company_name_css"].='background:red';

But I need to get the value of the number of child records. I searched and searched on the forums, but I can't seem to find it. I don't want to have to do a query on the table since I am pretty sure the value of the child records should already be available as an object property somewhere. Am I missing something obvious?

Thanks in advance for your help.

C
Chris Whitehead 3/6/2025

The method I'd use would be a sub query in the query section.

So if you add something like this to the fields bit.
(SELECT COUNT(*) FROM child_table WHERE company_details=item_id) as child_count,

The count will then appear as a field in the list with the name child_count.

C
cristi 3/7/2025

Use this for inspiration.

P
psiconsultants author 3/7/2025

Great, I'll take a look at the other link. I think my users would love this approach.