Frank Schneider Posted December 14, 2021 Share Posted December 14, 2021 I have a page member, and i want count a field wich have same entry. /* Kategorie */ $siteconfig["kategorie"] = array(); $siteconfig["kategorie"][] = "Mitglied"; $siteconfig["kategorie"][] = "Probetraining"; $siteconfig["kategorie"][] = "Zehnerkarte"; $siteconfig["kategorie"][] = "Ehemaliges Mitglied"; $siteconfig["kategorie"][] = "Personal"; $siteconfig["kategorie"][] = "Abo"; $siteconfig["kategorie"][] = "Neuanmeldung"; sort($siteconfig["kategorie"]); I want count member who has Zehnerkarte, i do as folow but get all member //========================================================================================= // //========================================================================================= function get_zehner($page) { $selector = "template=mitglied,mitglied_kategorie==Zehnerkarte"; $ret=$page->count($selector); return($ret); } How i can filter to "Zehnerkarte" Link to comment Share on other sites More sharing options...
kp52 Posted December 14, 2021 Share Posted December 14, 2021 $selector = "template=mitglied,mitglied_kategorie==Zehnerkarte"; Try it with just a single equals sign for category: $selector = "template=mitglied,mitglied_kategorie=Zehnerkarte"; Link to comment Share on other sites More sharing options...
Frank Schneider Posted December 15, 2021 Author Share Posted December 15, 2021 i do but same effect Link to comment Share on other sites More sharing options...
horst Posted December 15, 2021 Share Posted December 15, 2021 How do you add the category to the member pages? Through which type of field? Options Select, Page Reference, ...? Link to comment Share on other sites More sharing options...
Frank Schneider Posted December 15, 2021 Author Share Posted December 15, 2021 /* Kategorie */ $siteconfig["kategorie"] = array(); $siteconfig["kategorie"][] = "Mitglied"; $siteconfig["kategorie"][] = "Probetraining"; $siteconfig["kategorie"][] = "Zehnerkarte"; $siteconfig["kategorie"][] = "Ehemaliges Mitglied"; $siteconfig["kategorie"][] = "Personal"; $siteconfig["kategorie"][] = "Abo"; $siteconfig["kategorie"][] = "Neuanmeldung"; sort($siteconfig["kategorie"]); <!-- Kategorie --> <div class="col-lg-2"> <div class="form-group"> <label class="form-control-label">Kategorie: </label> <select class="form-control " name="Kategorie" data-placeholder="Kategorie wählen" > <?php foreach ($siteconfig["kategorie"] as $kategorie) { if ($mitglied->mitglied_kategorie == $form_fields['kategorie']['value']) { echo "<option value='".$kategorie."' selected='selected'>".$kategorie."</option>\n"; } else {echo "<option value='".$kategorie."'>".$kategorie."</option>\n";} } ?> </select> </div> </div> //Save $mitglied->mitglied_kategorie = $_POST['Kategorie']; //Filter return count the kategorie <?php //========================================================================================= // //========================================================================================= function get_zehner($page) { $selector = "template=mitglied,mitglied_kategorie=Zehnerkarte"; $ret=$page->count($selector); return($ret); } //========================================================================================= // //========================================================================================= function get_member($page) { $selector = "template=mitglied,mitglied_kategorie=Mitglied"; $ret=$page->count($selector); return($ret); } Link to comment Share on other sites More sharing options...
horst Posted December 15, 2021 Share Posted December 15, 2021 I do not understand. I asked for the field type of mitglied_kategorie. 1 Link to comment Share on other sites More sharing options...
Jan Romero Posted December 15, 2021 Share Posted December 15, 2021 Please show how you call get_zehner(). It looks like you’re passing in a Page object $page, but Page has no method count() that takes a selector. You can only call it without any arguments and it will give you the number of children of that page: https://processwire.com/api/ref/page/count/. Perhaps you want to use pages()->count($selector)? Also, this line is outside of <?php ?> tags and will not be executed: $mitglied->mitglied_kategorie = $_POST['Kategorie']; Also, please indent and use the forum’s code feature. 1 Link to comment Share on other sites More sharing options...
Frank Schneider Posted December 16, 2021 Author Share Posted December 16, 2021 Here is the call. <h1><?php echo get_zehner($pages->get("/mitglieder")) ?></h1> Field typ of mitglied_kategorie is text Link to comment Share on other sites More sharing options...
Jan Romero Posted December 16, 2021 Share Posted December 16, 2021 y not function get_zehner($page) { return wire('pages')->count("parent={$page}, template=mitglied, mitglied_kategorie=Zehnerkarte"); } or even function get_zehner() { return wire('pages')->count("parent=/mitglieder/, template=mitglied, mitglied_kategorie=Zehnerkarte"); } I would additionally rename the function to something like anzahlZehnerkarte, because I would probably expect "get_zehner" to return a PageArray. 1 Link to comment Share on other sites More sharing options...
Frank Schneider Posted December 17, 2021 Author Share Posted December 17, 2021 this works thank you Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now