This topic is locked

Show count of matching records on add page

10/18/2020 10:59:54 AM
PHPRunner General questions
D
david22585 author

I'm trying to show the count of records that match 1 value (account_id) on an add page. The main field is an address field, which auto fills in the account_id field. When the account_id field has a change, I use a field event to show a button that you can click to show matching records. I want to show the total count of records that match the account_id field as well before clicking the button. I tried to create an alias field for count, as totalcount. I tried to use the autofill of address to also autofill the accont_id on the alias field, and I used this code to no success:



if ($value["totalcount"] == ""){

} else {

$rs = DB::Query("SELECT count(id) AS cnt FROM addresses WHERE account_id=".$value["account_id"]."");

$data = $rs->fetchAssoc();

}

$value = $data["cnt"];


Doing this, it shows the value as the account_id, and not the $data["cnt"] as I was hoping for. I was wondering if anyone had a better solution or not. The field can change dynamically depending on if the wrong address is initially selected. It changes this way, but only shows the account_id number and not the count.

H
Hd_Mersintarim 10/18/2020

$rs = DB::Query("SELECT count(id) AS cnt FROM addresses WHERE account_id=".$value["account_id"]."");

try this
WHERE account_id='".$value["account_id"]."'");